From b41fe4a9fc64499a48fab6f9eb65bf98254dd0f5 Mon Sep 17 00:00:00 2001 From: jakeg00dwin Date: Sun, 28 Jul 2024 15:26:26 -0700 Subject: [PATCH] Added code and tests for tracking the setup() function usage --- mocks/MockADC/MockADC.c | 11 ++++++++++- mocks/MockADC/MockADC.h | 1 + src/ADC/ADC.c | 9 --------- tests/MockADC/test_MockADC.cpp | 9 +++++++++ 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/mocks/MockADC/MockADC.c b/mocks/MockADC/MockADC.c index 8c55769..a47f8a9 100644 --- a/mocks/MockADC/MockADC.c +++ b/mocks/MockADC/MockADC.c @@ -13,10 +13,13 @@ uint16_t fake_data[FAKESIZE]; int fake_index = 0; +static bool is_setup = false; + void ADC_Setup(void) { - + is_setup = true; + return; } void ADC_Init(uint8_t pin_num) @@ -68,3 +71,9 @@ int MockADC_GetIndex(void) { return fake_index; } + + +bool MockADC_IsSetup(void) +{ + return is_setup; +} diff --git a/mocks/MockADC/MockADC.h b/mocks/MockADC/MockADC.h index c69e6ad..0624b04 100644 --- a/mocks/MockADC/MockADC.h +++ b/mocks/MockADC/MockADC.h @@ -24,5 +24,6 @@ extern uint16_t (*ADC_ReadValue)(uint8_t pin_num); void MockADC_PushValue(uint16_t value); void MockADC_ZeroIndex(void); int MockADC_GetIndex(void); +bool MockADC_IsSetup(void); #endif //MOCKADC_H diff --git a/src/ADC/ADC.c b/src/ADC/ADC.c index f468fea..dc8eda0 100644 --- a/src/ADC/ADC.c +++ b/src/ADC/ADC.c @@ -63,20 +63,11 @@ void ADC_Init(uint8_t pin_num) //Disable input buffer //We do some kinda nasty address addition but it saves //memory and means we don't need a switch statment. - //PORT_ISC_INPUT_DISABLE_gc RegEdit_SetBit( (void *) (&PORTA.PIN0CTRL)+pin_num, PORT_ISC_INPUT_DISABLE_gc ); - //Ensure we use full 10bit resolution - //RegEdit_ClearBit((void *) &ADC0.CTRLA, 2); - - //Use VDD as our voltage refernce. - //RegEdit_SetBit((void *) &ADC0.CTRLC, 4); - - //We setup the ADC to take 32 samples. - //RegEdit_OR_Num((void *) &ADC0.CTRLB, 0x5); } diff --git a/tests/MockADC/test_MockADC.cpp b/tests/MockADC/test_MockADC.cpp index 45380c2..c2a86ea 100644 --- a/tests/MockADC/test_MockADC.cpp +++ b/tests/MockADC/test_MockADC.cpp @@ -84,3 +84,12 @@ TEST(test_MockADC, MockADC_PushValueDoesntOverflowArray) CHECK_TRUE(MockADC_GetIndex() <= 255); } } + +TEST(test_MockADC, MockADC_SetupSetsGlobal) +{ + CHECK_FALSE(MockADC_IsSetup()); + + ADC_Setup(); + + CHECK_TRUE(MockADC_IsSetup()); +}