From b103fe2b9799620da7bbb02e9d080073ee7f1c1e Mon Sep 17 00:00:00 2001 From: jake Date: Sat, 22 Feb 2025 21:31:52 -0800 Subject: [PATCH 01/19] removed error line, causes issues with LSP. --- src/main.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.c b/src/main.c index ddaf568..92d4425 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,4 @@ #ifndef F_CPU -#error "F_CPU not defined: defaulting to 9.6MHz" #define F_CPU 1200000UL #endif From 6167089a287ca5f2db0ead22fa88250d8ed8c666 Mon Sep 17 00:00:00 2001 From: jake Date: Sat, 22 Feb 2025 22:00:44 -0800 Subject: [PATCH 02/19] Added onto init tests. --- mocks/MockADC/MockADC.c | 12 ++++++------ mocks/MockADC/MockADC.h | 6 +++--- src/ADC/ADC.c | 41 ++++++++++++++++++++++++++++------------- src/ADC/ADC.h | 12 ++++++------ src/main.c | 12 ++++++------ tests/ADC/test_ADC.cpp | 25 +++++++++++++++++++++++-- 6 files changed, 72 insertions(+), 36 deletions(-) diff --git a/mocks/MockADC/MockADC.c b/mocks/MockADC/MockADC.c index dcf8f8f..b659746 100644 --- a/mocks/MockADC/MockADC.c +++ b/mocks/MockADC/MockADC.c @@ -17,7 +17,7 @@ static bool is_setup = false; -void ADC_SetPin(uint8_t pin_num) +void ADC_SetPin(uint8_t adc_chan) { return; } @@ -28,10 +28,10 @@ void ADC_Setup(void) return; } -void ADC_Init(uint8_t pin_num) +void ADC_Init(uint8_t adc_chan) { mock_c()->actualCall("ADC_Init") - ->withUnsignedIntParameters("pin_num", pin_num); + ->withUnsignedIntParameters("adc_chan", adc_chan); } void ADC_Enable(void) @@ -44,10 +44,10 @@ void ADC_Disable() mock_c()->actualCall("ADC_Disable"); } -uint16_t ADC_ReadValue_Impl(uint8_t pin_num) +uint16_t ADC_ReadValue_Impl(uint8_t adc_chan) { mock_c()->actualCall("ADC_ReadValue_Impl") - ->withUnsignedIntParameters("pin_num", pin_num); + ->withUnsignedIntParameters("adc_chan", adc_chan); if(fake_index == 0){ return 0; @@ -55,7 +55,7 @@ uint16_t ADC_ReadValue_Impl(uint8_t pin_num) return fake_data[--fake_index]; } -uint16_t (*ADC_ReadValue)(uint8_t pin_num) = ADC_ReadValue_Impl; +uint16_t (*ADC_ReadValue)(uint8_t adc_chan) = ADC_ReadValue_Impl; void MockADC_PushValue(uint16_t value){ diff --git a/mocks/MockADC/MockADC.h b/mocks/MockADC/MockADC.h index 6c95934..587daac 100644 --- a/mocks/MockADC/MockADC.h +++ b/mocks/MockADC/MockADC.h @@ -15,12 +15,12 @@ void ADC_Setup(void); -void ADC_SetPin(uint8_t pin_num); -void ADC_Init(uint8_t pin_num); +void ADC_SetPin(uint8_t adc_chan); +void ADC_Init(uint8_t adc_chan); void ADC_Enable(void); void ADC_Disable(void); -extern uint16_t (*ADC_ReadValue)(uint8_t pin_num); +extern uint16_t (*ADC_ReadValue)(uint8_t adc_chan); void MockADC_PushValue(uint16_t value); void MockADC_ZeroIndex(void); diff --git a/src/ADC/ADC.c b/src/ADC/ADC.c index 0e2075b..21c9532 100644 --- a/src/ADC/ADC.c +++ b/src/ADC/ADC.c @@ -13,10 +13,25 @@ #include "RegEdit.h" #include "avr/io.h" -#define MAX_PIN_NUM 7 +#define MAX_CHANNEL_NUM 3 -static bool IsInvalidPin(uint8_t pin_num) { - if (pin_num > MAX_PIN_NUM) { +static uint8_t GetChannelPinNum(uint8_t adc_chan) { + switch (adc_chan) { + case 0: + return PB5; + case 1: + return PB2; + case 2: + return PB4; + case 3: + return PB3; + default: + return 255; /*return invalid pin num.*/ + } +} + +static bool IsInvalidChannel(uint8_t adc_chan) { + if (adc_chan > MAX_CHANNEL_NUM) { return true; } return false; @@ -36,22 +51,22 @@ void ADC_Setup(void) { RegEdit_AND_Num((void *)&ADCSRB, (1 << ADTS2) | (0 << ADTS1) | (1 << ADTS0)); } -void ADC_Init(uint8_t pin_num) { +void ADC_Init(uint8_t adc_chan) { - if (IsInvalidPin(pin_num)) { + if (IsInvalidChannel(adc_chan)) { return; } // set the direction to input - // RegEdit_ClearBit((void *)&PORTA.DIR, pin_num); + RegEdit_ClearBit((void *)&DDRB, adc_chan); // Disable the pull-up resistor - // RegEdit_ClearBit((void *)&PORTA.OUT, pin_num); + RegEdit_ClearBit((void *)&PORTB, adc_chan); // Disable input buffer // We do some kinda nasty address addition but it saves // memory and means we don't need a switch statment. - // RegEdit_SetBit((void *)(&PORTA.PIN0CTRL) + pin_num, + // RegEdit_SetBit((void *)(&PORTA.PIN0CTRL) + adc_chan, // PORT_ISC_INPUT_DISABLE_gc); } @@ -65,15 +80,15 @@ void ADC_Disable() { // RegEdit_ClearBit((void *)&ADC0.CTRLA, 0); } -void ADC_SetPin(uint8_t pin_num) { - if (IsInvalidPin(pin_num)) { +void ADC_SetPin(uint8_t adc_chan) { + if (IsInvalidChannel(adc_chan)) { return; } // RegEdit_ClearRegister((void *)&ADC0.MUXPOS); - // RegEdit_SetNum((void *)&ADC0.MUXPOS, pin_num); + // RegEdit_SetNum((void *)&ADC0.MUXPOS, adc_chan); } -uint16_t ADC_ReadValue_Impl(uint8_t pin_num) { +uint16_t ADC_ReadValue_Impl(uint8_t adc_chan) { // RegEdit_SetNum((void *)&ADC0.COMMAND, ADC_STCONV_bm); /* Wait until ADC conversion done */ @@ -94,4 +109,4 @@ uint16_t ADC_ReadValue_Impl(uint8_t pin_num) { } // Set the default for the function pointer. -uint16_t (*ADC_ReadValue)(uint8_t pin_num) = ADC_ReadValue_Impl; +uint16_t (*ADC_ReadValue)(uint8_t adc_chan) = ADC_ReadValue_Impl; diff --git a/src/ADC/ADC.h b/src/ADC/ADC.h index 896c8ff..c369fa6 100644 --- a/src/ADC/ADC.h +++ b/src/ADC/ADC.h @@ -16,7 +16,7 @@ /** * @brief Initializes the AVR hardware in order to accept * Input for ADC usage. - * @param pin_num The number of the pin 0-7 you are initializing. + * @param adc_chan The channel of the pin 0-7 you are initializing. * * This function only makes use of PORTA by default. It sets the direction * register to input, disables the pull-up resistor and also diables interrupts @@ -25,7 +25,7 @@ * This in turn helps reduce noise when using the ADC. * */ -void ADC_Init(uint8_t pin_num); +void ADC_Init(uint8_t adc_chan); /** * @brief Enables the ADC @@ -40,12 +40,12 @@ void ADC_Disable(); /** * @brief Reads ADC value into variable * - * @param pin_num The bin number of the ADC pin being read. + * @param adc_chan The bin number of the ADC pin being read. * * This function depends on the ADC already being initialized and enabled * before being called. */ -extern uint16_t (*ADC_ReadValue)(uint8_t pin_num); +extern uint16_t (*ADC_ReadValue)(uint8_t adc_chan); /** * @brief Sets up the ADC @@ -61,8 +61,8 @@ void ADC_Setup(void); /** * @brief Sets the pin used in the MUX for ADC0. * - * @param pin_num The number of the pin in Port A. + * @param adc_chan The number of the pin in Port A. */ -void ADC_SetPin(uint8_t pin_num); +void ADC_SetPin(uint8_t adc_chan); #endif // ADC_H diff --git a/src/main.c b/src/main.c index 92d4425..b3e13e1 100644 --- a/src/main.c +++ b/src/main.c @@ -3,7 +3,7 @@ #endif #include "main.h" -//#include "ADC.h" +// #include "ADC.h" #include #include #include @@ -50,7 +50,7 @@ int main() { while (1) { UpdateButtonOutput(&btn1); UpdateButtonInput(&btn1); - //MotorMoveTo(0); + // MotorMoveTo(0); } return 0; @@ -97,8 +97,8 @@ uint8_t ReadSpeed(void) { uint8_t val = (uint8_t)(ADC >> 2); - //Map the speed value to the 100%-50% duty cycle range. - //val = (uint8_t)( (float)val / 255.0 ) * 100; + // Map the speed value to the 100%-50% duty cycle range. + // val = (uint8_t)( (float)val / 255.0 ) * 100; return val; } @@ -142,7 +142,7 @@ void MotorMoveTo(uint8_t target) { uint8_t on_delay = ReadSpeed(); uint8_t pos = (uint8_t)(ReadFader() >> 2); - uint8_t idx =0; + uint8_t idx = 0; while (diff(target, pos) > 8) { on_delay = ReadSpeed(); @@ -158,7 +158,7 @@ void MotorMoveTo(uint8_t target) { _delay_us(MOTOR_PULSE); } MotorCoast(); - for (;idx < 255; idx++) { + for (; idx < 255; idx++) { _delay_us(MOTOR_PULSE); } } diff --git a/tests/ADC/test_ADC.cpp b/tests/ADC/test_ADC.cpp index 7c4ce42..292d30c 100644 --- a/tests/ADC/test_ADC.cpp +++ b/tests/ADC/test_ADC.cpp @@ -73,12 +73,33 @@ TEST(test_ADC, ADC_SetupSetsRegisters) ADC_Setup(); } +TEST(test_ADC, ADC_InitRejectsInvalidChannels) +{ + for(uint8_t i = 4; i < 255; i++){ + ADC_Init(i); + } +} + TEST(test_ADC, ADC_InitPortbADC3UsesCorrectRegisters) { //PB3/ADC3 + //uint8_t adc_channel = 3; + uint8_t pin_num = 3; //Check it disables the pin's digital circuitry - + + //Check it sets the pin for input + mock().expectOneCall("RegEdit_ClearBit") + .withPointerParameter("reg", (void *) &DDRB) + .withUnsignedIntParameter("bit_num", pin_num); + + + //Check that the pull-up resistor is disabled. + mock().expectOneCall("RegEdit_ClearBit") + .withPointerParameter("reg", (void *) &PORTB) + .withUnsignedIntParameter("bit_num", pin_num); + + //Check that the ADC pin is selected in ADMUX @@ -102,7 +123,7 @@ TEST(test_ADC, ADC_InitPortbADC3UsesCorrectRegisters) .withUnsignedIntParameter("bit_num", PORT_ISC_INPUT_DISABLE_gc); */ - ADC_Init(7); + ADC_Init(3); } TEST(test_ADC, ADC_InitPortAPin0UsesCorrectRegisters) From a00e17667563fd2fd6877ff5eb02348361797ec3 Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 23 Feb 2025 09:50:09 -0800 Subject: [PATCH 03/19] Added testing for the pin number and resolving it from a adc channel input. --- src/ADC/ADC.c | 35 +++++++++++++----------- src/ADC/ADC.h | 6 +++++ tests/ADC/test_ADC.cpp | 61 +++++++++++++++++++----------------------- 3 files changed, 53 insertions(+), 49 deletions(-) diff --git a/src/ADC/ADC.c b/src/ADC/ADC.c index 21c9532..e0f558c 100644 --- a/src/ADC/ADC.c +++ b/src/ADC/ADC.c @@ -15,7 +15,14 @@ #define MAX_CHANNEL_NUM 3 -static uint8_t GetChannelPinNum(uint8_t adc_chan) { +static bool IsInvalidChannel(uint8_t adc_chan) { + if (adc_chan > MAX_CHANNEL_NUM) { + return true; + } + return false; +} + +uint8_t ADC_GetChannelPinNum(uint8_t adc_chan) { switch (adc_chan) { case 0: return PB5; @@ -30,13 +37,6 @@ static uint8_t GetChannelPinNum(uint8_t adc_chan) { } } -static bool IsInvalidChannel(uint8_t adc_chan) { - if (adc_chan > MAX_CHANNEL_NUM) { - return true; - } - return false; -} - void ADC_Setup(void) { // Clear the register, set VCC as ref, ADC0 as channel and // leave result right adjusted. @@ -57,17 +57,22 @@ void ADC_Init(uint8_t adc_chan) { return; } + // get the associated pin number. + uint8_t pin_num = ADC_GetChannelPinNum(adc_chan); + // set the direction to input - RegEdit_ClearBit((void *)&DDRB, adc_chan); + RegEdit_ClearBit((void *)&DDRB, pin_num); // Disable the pull-up resistor - RegEdit_ClearBit((void *)&PORTB, adc_chan); + RegEdit_ClearBit((void *)&PORTB, 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. - // RegEdit_SetBit((void *)(&PORTA.PIN0CTRL) + adc_chan, - // PORT_ISC_INPUT_DISABLE_gc); + // Set the adc mux reg for our channel. + + // Clear the existing mux bits. + RegEdit_AND_Num((void *)&ADMUX, 0xFC); + + // Set the correct bits + RegEdit_OR_Num((void *)&ADMUX, adc_chan); } void ADC_Enable(void) { diff --git a/src/ADC/ADC.h b/src/ADC/ADC.h index c369fa6..33c6026 100644 --- a/src/ADC/ADC.h +++ b/src/ADC/ADC.h @@ -27,6 +27,12 @@ */ void ADC_Init(uint8_t adc_chan); +/** + * @brief Returns the pin number for the adc channel or 255 on an error. + * @param The ADC channel. + */ +uint8_t ADC_GetChannelPinNum(uint8_t adc_chan); + /** * @brief Enables the ADC */ diff --git a/tests/ADC/test_ADC.cpp b/tests/ADC/test_ADC.cpp index 292d30c..69ddd19 100644 --- a/tests/ADC/test_ADC.cpp +++ b/tests/ADC/test_ADC.cpp @@ -80,50 +80,43 @@ TEST(test_ADC, ADC_InitRejectsInvalidChannels) } } -TEST(test_ADC, ADC_InitPortbADC3UsesCorrectRegisters) + +TEST(test_ADC, ADC_InitPortbWorksWithValidChannels) { - //PB3/ADC3 - //uint8_t adc_channel = 3; - uint8_t pin_num = 3; + uint8_t pin_num; - //Check it disables the pin's digital circuitry + for(uint8_t adc_channel = 0; adc_channel <= 3; adc_channel++) + { + pin_num = ADC_GetChannelPinNum(adc_channel); - //Check it sets the pin for input - mock().expectOneCall("RegEdit_ClearBit") - .withPointerParameter("reg", (void *) &DDRB) - .withUnsignedIntParameter("bit_num", pin_num); + //Check it disables the pin's digital circuitry + + //Check it sets the pin for input + mock().expectOneCall("RegEdit_ClearBit") + .withPointerParameter("reg", (void *) &DDRB) + .withUnsignedIntParameter("bit_num", pin_num); - //Check that the pull-up resistor is disabled. - mock().expectOneCall("RegEdit_ClearBit") - .withPointerParameter("reg", (void *) &PORTB) - .withUnsignedIntParameter("bit_num", pin_num); + //Check that the pull-up resistor is disabled. + mock().expectOneCall("RegEdit_ClearBit") + .withPointerParameter("reg", (void *) &PORTB) + .withUnsignedIntParameter("bit_num", pin_num); - //Check that the ADC pin is selected in ADMUX - + //Check that the ADC pin is selected in ADMUX - // + //Clears the last two bits first. + mock().expectOneCall("RegEdit_AND_Num") + .withPointerParameter("reg", (void *) &ADMUX) + .withUnsignedIntParameter("num", 0xFC); - /* - //Check for setting the direction to input. - mock().expectOneCall("RegEdit_ClearBit") - .withPointerParameter("reg", (void *) &PORTA.DIR) - .withUnsignedIntParameter("bit_num", 7); - - //Check that the pullup is off - mock().expectOneCall("RegEdit_ClearBit") - .withPointerParameter("reg", (void *) &PORTA.OUT) - .withUnsignedIntParameter("bit_num", 7); + //Selects the ADC pin/channel + mock().expectOneCall("RegEdit_OR_Num") + .withPointerParameter("reg", (void *) &ADMUX) + .withUnsignedIntParameter("num", adc_channel); - //Set the ISC(input sense config) to disable digital input - //buffering and reduce the noise on ADC usage. - mock().expectOneCall("RegEdit_SetBit") - .withPointerParameter("reg", (void *) &PORTA.PIN7CTRL) - .withUnsignedIntParameter("bit_num", PORT_ISC_INPUT_DISABLE_gc); - - */ - ADC_Init(3); + ADC_Init(adc_channel); + } } TEST(test_ADC, ADC_InitPortAPin0UsesCorrectRegisters) From 969b852cb3364e55e582abce57f66a1870ad0a12 Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 23 Feb 2025 09:58:30 -0800 Subject: [PATCH 04/19] Added test for adc enable. + code for testing ADC enable. + code for passing ADC enable function test. --- src/ADC/ADC.c | 2 +- tests/ADC/test_ADC.cpp | 41 +++++++---------------------------------- 2 files changed, 8 insertions(+), 35 deletions(-) diff --git a/src/ADC/ADC.c b/src/ADC/ADC.c index e0f558c..0893392 100644 --- a/src/ADC/ADC.c +++ b/src/ADC/ADC.c @@ -77,7 +77,7 @@ void ADC_Init(uint8_t adc_chan) { void ADC_Enable(void) { // Set the enable bit in the CTRLA register - // RegEdit_SetBit((void *)&ADC0.CTRLA, 0); + RegEdit_SetBit((void *)&ADCSRA, ADEN); } void ADC_Disable() { diff --git a/tests/ADC/test_ADC.cpp b/tests/ADC/test_ADC.cpp index 69ddd19..2308ed3 100644 --- a/tests/ADC/test_ADC.cpp +++ b/tests/ADC/test_ADC.cpp @@ -119,46 +119,18 @@ TEST(test_ADC, ADC_InitPortbWorksWithValidChannels) } } -TEST(test_ADC, ADC_InitPortAPin0UsesCorrectRegisters) -{ - /* - //Check for setting the direction to input. - mock().expectOneCall("RegEdit_ClearBit") - .withPointerParameter("reg", (void *) &PORTA.DIR) - .withUnsignedIntParameter("bit_num", 0); - - //Check that the pullup is off - mock().expectOneCall("RegEdit_ClearBit") - .withPointerParameter("reg", (void *) &PORTA.OUT) - .withUnsignedIntParameter("bit_num", 0); - - //Set the ISC(input sense config) to disable digital input - //buffering and reduce the noise on ADC usage. - mock().expectOneCall("RegEdit_SetBit") - .withPointerParameter("reg", (void *) &PORTA.PIN0CTRL) - .withUnsignedIntParameter("bit_num", PORT_ISC_INPUT_DISABLE_gc); - - */ - //ADC_Init(0); -} - -TEST(test_ADC, ADC_InitDoesNothingOnHighPinNumbers) -{ - //mock().expectNoCall("RegEdit_SetBit"); - //ADC_Init(8); -} TEST(test_ADC, ADC_EnablePasses) { - /* - mock().expectOneCall("RegEdit_SetBit") - .withPointerParameter("reg", (void *) &ADC0.CTRLA) - .withUnsignedIntParameter("bit_num", 0); - */ - //ADC_Enable(); + mock().expectOneCall("RegEdit_SetBit") + .withPointerParameter("reg", (void *) &ADCSRA) + .withUnsignedIntParameter("bit_num", ADEN); + + ADC_Enable(); } + TEST(test_ADC, ADC_DisablePasses) { /* @@ -169,6 +141,7 @@ TEST(test_ADC, ADC_DisablePasses) //ADC_Disable(); } + TEST(test_ADC, ADC_SetPinSetsRightRegisters) { /* From 352ee9e6a86ec656d3993c9010afccd7941c07ab Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 23 Feb 2025 09:59:52 -0800 Subject: [PATCH 05/19] Added test for ADC_Disable() --- tests/ADC/test_ADC.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/ADC/test_ADC.cpp b/tests/ADC/test_ADC.cpp index 2308ed3..cdc7a97 100644 --- a/tests/ADC/test_ADC.cpp +++ b/tests/ADC/test_ADC.cpp @@ -133,12 +133,11 @@ TEST(test_ADC, ADC_EnablePasses) TEST(test_ADC, ADC_DisablePasses) { - /* mock().expectOneCall("RegEdit_ClearBit") - .withPointerParameter("reg", (void *) &ADC0.CTRLA) - .withUnsignedIntParameter("bit_num", 0); - */ - //ADC_Disable(); + .withPointerParameter("reg", (void *) &ADCSRA) + .withUnsignedIntParameter("bit_num", ADEN); + + ADC_Disable(); } From 90891545d1147e23c4dc901a252f3d440f4368d9 Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 23 Feb 2025 10:00:38 -0800 Subject: [PATCH 06/19] Added code to pass the `ADC_Disable()` function. --- src/ADC/ADC.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ADC/ADC.c b/src/ADC/ADC.c index 0893392..529498c 100644 --- a/src/ADC/ADC.c +++ b/src/ADC/ADC.c @@ -82,7 +82,7 @@ void ADC_Enable(void) { void ADC_Disable() { // Clear the enable ADC flag - // RegEdit_ClearBit((void *)&ADC0.CTRLA, 0); + RegEdit_ClearBit((void *)&ADCSRA, ADEN); } void ADC_SetPin(uint8_t adc_chan) { From fc3d0d11a54169c326ba5e03934d2b4f2af2cc0b Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 23 Feb 2025 10:03:21 -0800 Subject: [PATCH 07/19] removed now uneeded functions. --- mocks/MockADC/MockADC.c | 6 ------ mocks/MockADC/MockADC.h | 1 - src/ADC/ADC.c | 7 ------- src/ADC/ADC.h | 7 +------ tests/ADC/test_ADC.cpp | 22 ---------------------- 5 files changed, 1 insertion(+), 42 deletions(-) diff --git a/mocks/MockADC/MockADC.c b/mocks/MockADC/MockADC.c index b659746..7673ccd 100644 --- a/mocks/MockADC/MockADC.c +++ b/mocks/MockADC/MockADC.c @@ -16,12 +16,6 @@ int fake_index = 0; static bool is_setup = false; - -void ADC_SetPin(uint8_t adc_chan) -{ - return; -} - void ADC_Setup(void) { is_setup = true; diff --git a/mocks/MockADC/MockADC.h b/mocks/MockADC/MockADC.h index 587daac..c6c4480 100644 --- a/mocks/MockADC/MockADC.h +++ b/mocks/MockADC/MockADC.h @@ -15,7 +15,6 @@ void ADC_Setup(void); -void ADC_SetPin(uint8_t adc_chan); void ADC_Init(uint8_t adc_chan); void ADC_Enable(void); void ADC_Disable(void); diff --git a/src/ADC/ADC.c b/src/ADC/ADC.c index 529498c..7cfc8d3 100644 --- a/src/ADC/ADC.c +++ b/src/ADC/ADC.c @@ -85,13 +85,6 @@ void ADC_Disable() { RegEdit_ClearBit((void *)&ADCSRA, ADEN); } -void ADC_SetPin(uint8_t adc_chan) { - if (IsInvalidChannel(adc_chan)) { - return; - } - // RegEdit_ClearRegister((void *)&ADC0.MUXPOS); - // RegEdit_SetNum((void *)&ADC0.MUXPOS, adc_chan); -} uint16_t ADC_ReadValue_Impl(uint8_t adc_chan) { // RegEdit_SetNum((void *)&ADC0.COMMAND, ADC_STCONV_bm); diff --git a/src/ADC/ADC.h b/src/ADC/ADC.h index 33c6026..7eb0f4e 100644 --- a/src/ADC/ADC.h +++ b/src/ADC/ADC.h @@ -27,6 +27,7 @@ */ void ADC_Init(uint8_t adc_chan); + /** * @brief Returns the pin number for the adc channel or 255 on an error. * @param The ADC channel. @@ -64,11 +65,5 @@ extern uint16_t (*ADC_ReadValue)(uint8_t adc_chan); */ void ADC_Setup(void); -/** - * @brief Sets the pin used in the MUX for ADC0. - * - * @param adc_chan The number of the pin in Port A. - */ -void ADC_SetPin(uint8_t adc_chan); #endif // ADC_H diff --git a/tests/ADC/test_ADC.cpp b/tests/ADC/test_ADC.cpp index cdc7a97..6e6047c 100644 --- a/tests/ADC/test_ADC.cpp +++ b/tests/ADC/test_ADC.cpp @@ -141,28 +141,6 @@ TEST(test_ADC, ADC_DisablePasses) } -TEST(test_ADC, ADC_SetPinSetsRightRegisters) -{ - /* - //It clears existing MUXPOS register values. - mock().expectOneCall("RegEdit_ClearRegister") - .withPointerParameter("reg", (void *) &ADC0.MUXPOS); - - //It Correctly sets the pin number. - mock().expectOneCall("RegEdit_SetNum") - .withPointerParameter("reg", (void *) &ADC0.MUXPOS) - .withUnsignedIntParameter("num", 4); - */ - //ADC_SetPin(4); -} - - -TEST(test_ADC, ADC_SetPinFailsOnInvalidPin) -{ - //ADC_SetPin(8); -} - - static uint16_t ADC_ReadValueFake(uint8_t pin_num) { return 512; From 58ab3c12eba25bba20c9d6e322311fdfe9c840be Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 23 Feb 2025 10:32:13 -0800 Subject: [PATCH 08/19] Added test for the ADC reading timeout feature --- tests/ADC/test_ADC.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tests/ADC/test_ADC.cpp b/tests/ADC/test_ADC.cpp index 6e6047c..1c5c03c 100644 --- a/tests/ADC/test_ADC.cpp +++ b/tests/ADC/test_ADC.cpp @@ -140,13 +140,32 @@ TEST(test_ADC, ADC_DisablePasses) ADC_Disable(); } +TEST(test_ADC, ADC_ReadValueImplimentationTimesOut) +{ + //Expect the start conversion bit to be set. + mock().expectOneCall("RegEdit_SetBit") + .withPointerParameter("reg", (void *) &ADCSRA) + .withUnsignedIntParameter("bit_num", ADSC); + + //Check that it can time out. + + //Expect it to read the start bit + mock().expectNCalls(ADC_WAIT_TIMEOUT, "RegEdit_IsBitSet") + .withPointerParameter("reg", (void *) &ADCSRA) + .withUnsignedIntParameter("bit_num", ADSC); + + //Check that it does return a value. + + ADC_ReadValue(0); +} + static uint16_t ADC_ReadValueFake(uint8_t pin_num) { return 512; } -TEST_GROUP(test_ADCRead) +TEST_GROUP(test_ADCReadPtrSwap) { void setup() { @@ -159,7 +178,7 @@ TEST_GROUP(test_ADCRead) } }; -TEST(test_ADCRead, FunctionPointerSwapWorks) +TEST(test_ADCReadPtrSwap, FunctionPointerSwapWorks) { uint16_t value = ADC_ReadValue(0); From c07fc415bff9d61e2f736c121fb78f609c42ee31 Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 23 Feb 2025 10:32:22 -0800 Subject: [PATCH 09/19] Added code to pass the ADC timeout feature --- src/ADC/ADC.c | 34 +++++++++++++++++++--------------- src/ADC/ADC.h | 8 ++++++-- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/ADC/ADC.c b/src/ADC/ADC.c index 7cfc8d3..c926891 100644 --- a/src/ADC/ADC.c +++ b/src/ADC/ADC.c @@ -85,25 +85,29 @@ void ADC_Disable() { RegEdit_ClearBit((void *)&ADCSRA, ADEN); } - uint16_t ADC_ReadValue_Impl(uint8_t adc_chan) { - // RegEdit_SetNum((void *)&ADC0.COMMAND, ADC_STCONV_bm); + if (IsInvalidChannel(adc_chan)) { + return UINT16_MAX; + } - /* Wait until ADC conversion done */ + // start conversion. + RegEdit_SetBit((void *)&ADCSRA, ADSC); - /* - while (!(ADC0.INTFLAGS & ADC_RESRDY_bm)) { - ; - } - */ + /* Wait until ADC conversion done or it times out. */ + uint8_t cycles = 1; + while (1) { + if (!RegEdit_IsBitSet((void *)&ADCSRA, ADSC)) { + break; + } + // if It times out return an invalid value for a 12bit ADC. + else if (cycles >= ADC_WAIT_TIMEOUT) { + return UINT16_MAX; + } + cycles++; + } - /* Clear the interrupt flag by writing 1: */ - // ADC0.INTFLAGS = ADC_RESRDY_bm; - - // uint16_t adc_val = (uint16_t)ADC0.RES; - uint16_t adc_val = 0; - adc_val = adc_val >> 5; - return adc_val; + uint8_t val = ADC; + return val; } // Set the default for the function pointer. diff --git a/src/ADC/ADC.h b/src/ADC/ADC.h index 7eb0f4e..6ad30ab 100644 --- a/src/ADC/ADC.h +++ b/src/ADC/ADC.h @@ -13,6 +13,12 @@ #include #include +/** + * @brief The number of loop cycles it waits for ADC conversion before + * timing out. + */ +#define ADC_WAIT_TIMEOUT 16 + /** * @brief Initializes the AVR hardware in order to accept * Input for ADC usage. @@ -27,7 +33,6 @@ */ void ADC_Init(uint8_t adc_chan); - /** * @brief Returns the pin number for the adc channel or 255 on an error. * @param The ADC channel. @@ -65,5 +70,4 @@ extern uint16_t (*ADC_ReadValue)(uint8_t adc_chan); */ void ADC_Setup(void); - #endif // ADC_H From 6736e30dd1cbf57c2fbc61f2877b370153e7781d Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 23 Feb 2025 10:34:23 -0800 Subject: [PATCH 10/19] Added extra testing/assert line for the returned error value. --- tests/ADC/test_ADC.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/ADC/test_ADC.cpp b/tests/ADC/test_ADC.cpp index 1c5c03c..04f1f6d 100644 --- a/tests/ADC/test_ADC.cpp +++ b/tests/ADC/test_ADC.cpp @@ -154,9 +154,10 @@ TEST(test_ADC, ADC_ReadValueImplimentationTimesOut) .withPointerParameter("reg", (void *) &ADCSRA) .withUnsignedIntParameter("bit_num", ADSC); - //Check that it does return a value. + //Check that it return the "error" value - ADC_ReadValue(0); + uint16_t value = ADC_ReadValue(0); + CHECK_EQUAL_TEXT(UINT16_MAX, value, "ERROR: Should return UINT16_MAX!"); } From 2add13a745a0fc223539b3a5eef2a07a2118f0f8 Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 23 Feb 2025 10:55:46 -0800 Subject: [PATCH 11/19] Modified ADC mock module to have the new function signiture for the `ADC_ReadValue()` --- mocks/MockADC/MockADC.c | 8 ++++---- mocks/MockADC/MockADC.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mocks/MockADC/MockADC.c b/mocks/MockADC/MockADC.c index 7673ccd..8465365 100644 --- a/mocks/MockADC/MockADC.c +++ b/mocks/MockADC/MockADC.c @@ -38,10 +38,10 @@ void ADC_Disable() mock_c()->actualCall("ADC_Disable"); } -uint16_t ADC_ReadValue_Impl(uint8_t adc_chan) +uint16_t ADC_ReadValue_Impl(void) { - mock_c()->actualCall("ADC_ReadValue_Impl") - ->withUnsignedIntParameters("adc_chan", adc_chan); + mock_c()->actualCall("ADC_ReadValue_Impl"); + if(fake_index == 0){ return 0; @@ -49,7 +49,7 @@ uint16_t ADC_ReadValue_Impl(uint8_t adc_chan) return fake_data[--fake_index]; } -uint16_t (*ADC_ReadValue)(uint8_t adc_chan) = ADC_ReadValue_Impl; +uint16_t (*ADC_ReadValue)(void) = ADC_ReadValue_Impl; void MockADC_PushValue(uint16_t value){ diff --git a/mocks/MockADC/MockADC.h b/mocks/MockADC/MockADC.h index c6c4480..c1d1be6 100644 --- a/mocks/MockADC/MockADC.h +++ b/mocks/MockADC/MockADC.h @@ -19,7 +19,7 @@ void ADC_Init(uint8_t adc_chan); void ADC_Enable(void); void ADC_Disable(void); -extern uint16_t (*ADC_ReadValue)(uint8_t adc_chan); +extern uint16_t (*ADC_ReadValue)(void); void MockADC_PushValue(uint16_t value); void MockADC_ZeroIndex(void); From de463a34699de4a2966e2eba37b666a0e8f8a198 Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 23 Feb 2025 10:56:00 -0800 Subject: [PATCH 12/19] Cleaned up ADC module --- src/ADC/ADC.c | 9 +++------ src/ADC/ADC.h | 3 +-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/ADC/ADC.c b/src/ADC/ADC.c index c926891..e441bf7 100644 --- a/src/ADC/ADC.c +++ b/src/ADC/ADC.c @@ -85,10 +85,7 @@ void ADC_Disable() { RegEdit_ClearBit((void *)&ADCSRA, ADEN); } -uint16_t ADC_ReadValue_Impl(uint8_t adc_chan) { - if (IsInvalidChannel(adc_chan)) { - return UINT16_MAX; - } +uint16_t ADC_ReadValue_Impl(void) { // start conversion. RegEdit_SetBit((void *)&ADCSRA, ADSC); @@ -106,9 +103,9 @@ uint16_t ADC_ReadValue_Impl(uint8_t adc_chan) { cycles++; } - uint8_t val = ADC; + uint16_t val = ADC; return val; } // Set the default for the function pointer. -uint16_t (*ADC_ReadValue)(uint8_t adc_chan) = ADC_ReadValue_Impl; +uint16_t (*ADC_ReadValue)(void) = ADC_ReadValue_Impl; diff --git a/src/ADC/ADC.h b/src/ADC/ADC.h index 6ad30ab..bc64912 100644 --- a/src/ADC/ADC.h +++ b/src/ADC/ADC.h @@ -52,12 +52,11 @@ void ADC_Disable(); /** * @brief Reads ADC value into variable * - * @param adc_chan The bin number of the ADC pin being read. * * This function depends on the ADC already being initialized and enabled * before being called. */ -extern uint16_t (*ADC_ReadValue)(uint8_t adc_chan); +extern uint16_t (*ADC_ReadValue)(); /** * @brief Sets up the ADC From 33b70d3283279289e3bbd82c0923eacc7e4ce847 Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 23 Feb 2025 10:56:13 -0800 Subject: [PATCH 13/19] Included the ADC module in main's linked libs --- src/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index aa33018..496bf11 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,6 +4,7 @@ add_executable(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME} RegEdit + ADC #timer ) From 82c16a7ddc8a0d42a0b9fbc73a97263d7417b4f4 Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 23 Feb 2025 10:56:38 -0800 Subject: [PATCH 14/19] Adjusted function signiture for `ADC_ReadValue()` --- tests/ADC/test_ADC.cpp | 6 +++--- tests/MockADC/test_MockADC.cpp | 8 +++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/ADC/test_ADC.cpp b/tests/ADC/test_ADC.cpp index 04f1f6d..a523296 100644 --- a/tests/ADC/test_ADC.cpp +++ b/tests/ADC/test_ADC.cpp @@ -156,12 +156,12 @@ TEST(test_ADC, ADC_ReadValueImplimentationTimesOut) //Check that it return the "error" value - uint16_t value = ADC_ReadValue(0); + uint16_t value = ADC_ReadValue(); CHECK_EQUAL_TEXT(UINT16_MAX, value, "ERROR: Should return UINT16_MAX!"); } -static uint16_t ADC_ReadValueFake(uint8_t pin_num) +static uint16_t ADC_ReadValueFake() { return 512; } @@ -181,7 +181,7 @@ TEST_GROUP(test_ADCReadPtrSwap) TEST(test_ADCReadPtrSwap, FunctionPointerSwapWorks) { - uint16_t value = ADC_ReadValue(0); + uint16_t value = ADC_ReadValue(); LONGS_EQUAL(512, value); } diff --git a/tests/MockADC/test_MockADC.cpp b/tests/MockADC/test_MockADC.cpp index 8b0b5ee..c7b16f9 100644 --- a/tests/MockADC/test_MockADC.cpp +++ b/tests/MockADC/test_MockADC.cpp @@ -55,10 +55,9 @@ TEST(test_MockADC, ADC_ReadValue) MockADC_ZeroIndex(); MockADC_PushValue(512); - mock().expectOneCall("ADC_ReadValue_Impl") - .withUnsignedIntParameter("pin_num", 0x2); + mock().expectOneCall("ADC_ReadValue_Impl"); - uint16_t val = ADC_ReadValue(0x2); + uint16_t val = ADC_ReadValue(); LONGS_EQUAL(512, val); } @@ -68,10 +67,9 @@ TEST(test_MockADC, ADC_ReadValueReturnsZeroOnEmptyBuffer) MockADC_ZeroIndex(); mock().expectOneCall("ADC_ReadValue_Impl") - .withUnsignedIntParameter("pin_num", 0x2) .andReturnValue(0x0000); - uint16_t val = ADC_ReadValue(0x2); + uint16_t val = ADC_ReadValue(); LONGS_EQUAL(0, val); } From 60b83865cd85c7649c2efb333e8e3fff2037cf80 Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 23 Feb 2025 10:56:48 -0800 Subject: [PATCH 15/19] Added mock test runner function to menu. --- otto.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/otto.sh b/otto.sh index 50416ce..0d10fca 100755 --- a/otto.sh +++ b/otto.sh @@ -224,12 +224,19 @@ run_c_tests () { make AllTests && ./tests/AllTests -c -v } +run_mock_tests () { + format_source_code + clear_cmake_cache + cmake -DUNIT_TESTING=ON -DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE} ../ + make Mock_Tests && ./tests/Mock_Tests -c -v +} + print_menu () { echo "BUILD MENU:" echo "0. Add Mock Module" echo "1. Run Tests" echo "2. Build Project(hex)" - echo "3. User Option" + echo "3. Run MockTests" echo "4. Flash to AVR" echo "5. Add new module to project" echo "6. Delete module from project" @@ -264,7 +271,7 @@ main() { 3) echo "You selected Option 3" valid_choice=true - build_hex_optimized + run_mock_tests ;; 4) echo "You selected Option 4" From c2ce883adbce50b45271472a5c76c451bda095a5 Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 23 Feb 2025 10:58:07 -0800 Subject: [PATCH 16/19] Mocking tests now passing after fixing param name. --- tests/MockADC/test_MockADC.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/MockADC/test_MockADC.cpp b/tests/MockADC/test_MockADC.cpp index c7b16f9..dbbd34e 100644 --- a/tests/MockADC/test_MockADC.cpp +++ b/tests/MockADC/test_MockADC.cpp @@ -30,7 +30,7 @@ TEST_GROUP(test_MockADC) TEST(test_MockADC, ADC_InitExpects) { mock().expectOneCall("ADC_Init") - .withUnsignedIntParameter("pin_num", 7); + .withUnsignedIntParameter("adc_chan", 7); ADC_Init(7); } From 78fdf54421732abc8c6413f8b9ef896c06b06eef Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 23 Feb 2025 10:58:42 -0800 Subject: [PATCH 17/19] Adjusted value for more accurate input. --- tests/MockADC/test_MockADC.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/MockADC/test_MockADC.cpp b/tests/MockADC/test_MockADC.cpp index dbbd34e..bb8d250 100644 --- a/tests/MockADC/test_MockADC.cpp +++ b/tests/MockADC/test_MockADC.cpp @@ -30,9 +30,9 @@ TEST_GROUP(test_MockADC) TEST(test_MockADC, ADC_InitExpects) { mock().expectOneCall("ADC_Init") - .withUnsignedIntParameter("adc_chan", 7); + .withUnsignedIntParameter("adc_chan", 0); - ADC_Init(7); + ADC_Init(0); } TEST(test_MockADC, ADC_EnableExpects) From 91ee864d2361cb0b0f08e2c63cf6f7e397da544f Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 23 Feb 2025 11:53:14 -0800 Subject: [PATCH 18/19] Removed the use of the tested ADC interface --- src/CMakeLists.txt | 4 ++-- src/main.c | 51 ++++++++++++++++++++++++++-------------------- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 496bf11..60a4ac6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,8 +3,8 @@ add_executable(${PROJECT_NAME} ) target_link_libraries(${PROJECT_NAME} - RegEdit - ADC + #RegEdit + #ADC #timer ) diff --git a/src/main.c b/src/main.c index b3e13e1..89176aa 100644 --- a/src/main.c +++ b/src/main.c @@ -3,7 +3,7 @@ #endif #include "main.h" -// #include "ADC.h" +//#include "ADC.h" #include #include #include @@ -33,7 +33,7 @@ volatile uint16_t tick_count; // ############################# static inline void InitTimer0(void); -static void InitBtn(btn_state *b, uint8_t input_pin, uint8_t output_pin); +static void InitBtn(btn_state *b, uint8_t input_pin); static void ClearButtonTimer(btn_state *b); static void StartButtonTimer(btn_state *b); static void CheckButtonLongpress(btn_state *b); @@ -50,7 +50,6 @@ int main() { while (1) { UpdateButtonOutput(&btn1); UpdateButtonInput(&btn1); - // MotorMoveTo(0); } return 0; @@ -64,7 +63,7 @@ void InitProg(void) { /*Set the debounced state to all high*/ debounced_state = 0xFF; - InitBtn(&btn1, BUTTON_PIN, PIN_ACTIVE1); + InitBtn(&btn1, BUTTON_PIN); /*Wait 5ms for pull-up resistors voltage to become stable.*/ _delay_ms(5); @@ -75,11 +74,11 @@ void InitProg(void) { // Checks against a bit pattern we defined to represent the start of data. if (eeprom_read_byte((uint8_t *)ROM_SP_ADR) == START_PATTERN) { - MotorMoveTo(eeprom_read_byte((uint8_t *)ROM_SS1_ADR)); + MotorMoveTo(eeprom_read_byte((uint8_t *)POSITION1_ADR)); } else { // otherwise we write the init values for the start pattern and states. eeprom_write_byte((uint8_t *)ROM_SP_ADR, START_PATTERN); - eeprom_write_byte((uint8_t *)ROM_SS1_ADR, 0x7F); + eeprom_write_byte((uint8_t *)POSITION1_ADR, 0x7F); } InitTimer0(); @@ -95,17 +94,18 @@ uint8_t ReadSpeed(void) { while (ADCSRA & (1 << ADSC)) { } // Wait for conversion to finish - uint8_t val = (uint8_t)(ADC >> 2); - - // Map the speed value to the 100%-50% duty cycle range. - // val = (uint8_t)( (float)val / 255.0 ) * 100; + //Normally a bitshift of 2 is done for 8bit ADC values, + //however we want to divide by two after this as well so we + //do a third shift followed by an addition of 127 to yield a mapping of + //approximatly 50%-96.6% duty cycle range. + uint8_t val = (uint8_t)(ADC >> 3) + 127; return val; } // change to ReadFader(void) uint16_t ReadFader(void) { - // Initialize ADC + // Initialize ADC ADMUX = (1 << MUX1) | (1 << MUX0); // Select ADC3 (PB3) ADCSRA = (1 << ADEN) | (1 << ADPS1) | (1 << ADPS0); // Enable ADC, prescaler 8 @@ -128,14 +128,15 @@ static inline uint8_t diff(uint8_t a, uint8_t b) { return b - a; } -void MotorSetSavePos() { +void MotorSetSavePos(uint8_t *ADR) { uint8_t pos = (uint8_t)(ReadFader() >> 2); - eeprom_write_byte((uint8_t *)ROM_SS1_ADR, pos); + //eeprom_write_byte((uint8_t *)ADR, pos); + eeprom_update_byte((uint8_t *)ADR, pos); return; } -uint8_t MotorGetSavedPos(void) { - return (uint8_t)eeprom_read_byte((uint8_t *)ROM_SS1_ADR); +uint8_t MotorGetSavedPos(uint8_t *ADR) { + return (uint8_t)eeprom_read_byte((uint8_t *)POSITION1_ADR); } void MotorMoveTo(uint8_t target) { @@ -190,21 +191,17 @@ void MotorCoast(void) { */ /*This is kinda like our button constructor*/ -static void InitBtn(btn_state *b, uint8_t input_pin, uint8_t output_pin) { +static void InitBtn(btn_state *b, uint8_t input_pin) { b->is_long_pressed = 0; b->is_pressed = 0; b->is_active = 0; b->pressed_ticks = 0; b->timer_enabled = 0; b->input_pin = input_pin; - b->output_pin = output_pin; /*Configure the buttons inputs and outputs*/ DDRB &= ~(1 << b->input_pin); PORTB |= (1 << b->input_pin); - - DDRB |= (1 << b->output_pin); - PORTB &= ~(1 << b->output_pin); } static void ClearButtonTimer(btn_state *b) { @@ -248,6 +245,7 @@ static void UpdateButtonOutput(btn_state *b) { /*Then start the timer and update the output*/ // ToggleOutput(b); StartButtonTimer(b); + return; } @@ -267,12 +265,21 @@ static void UpdateButtonOutput(btn_state *b) { else if (!b->is_pressed) { /*If the button was released on a long press.*/ if (b->is_long_pressed) { - MotorSetSavePos(); + MotorSetSavePos((uint8_t *)POSITION1_ADR); } /*If the button pres was a short one.*/ else if (!b->is_long_pressed) { if (b->is_active) { - MotorMoveTo(MotorGetSavedPos()); + /*Save the current position into position 2 EEPROM*/ + MotorSetSavePos((uint8_t *)POSITION2_ADR); + + /*If already in saved position then go back to original pos.*/ + if(diff(MotorGetSavedPos((uint8_t *)POSITION1_ADR), ReadFader()) > 8){ + MotorMoveTo(MotorGetSavedPos((uint8_t *)POSITION1_ADR)); + } + else{ + MotorMoveTo(MotorGetSavedPos((uint8_t *)POSITION1_ADR)); + } } else { MotorCoast(); } From deaa59f5a294c0e5903fec567aa54743a0321ed8 Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 23 Feb 2025 11:53:23 -0800 Subject: [PATCH 19/19] Changed names for save locations. --- inc/main.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/inc/main.h b/inc/main.h index 699994d..f72eb09 100644 --- a/inc/main.h +++ b/inc/main.h @@ -32,8 +32,8 @@ //Addresses in the eeprom for the two switch states #define ROM_SP_ADR 0x0 -#define ROM_SS1_ADR 0x1 -#define ROM_SS2_ADR 0x2 +#define POSITION1_ADR 0x1 +#define POSITION2_ADR 0x2 #define ROM_EP_ADR 0x3 //Debounce check number. @@ -89,7 +89,6 @@ typedef struct { uint8_t timer_enabled: 1; uint8_t pressed_ticks; uint8_t input_pin; - uint8_t output_pin; }btn_state;