Added function to select the ADC0.MUXPOS pins.

This commit is contained in:
jakeg00dwin 2024-07-28 15:49:01 -07:00
parent fae7509dba
commit 9e750af5bf
3 changed files with 29 additions and 1 deletions

View File

@ -13,11 +13,13 @@
#include "RegEdit.h"
#include "avr/io.h"
#define MAX_PIN_NUM 7
static uint8_t porta_out;
static uint8_t porta_dir;
static bool IsInvalidPin(uint8_t pin_num){
if(pin_num > 7){
if(pin_num > MAX_PIN_NUM){
return true;
}
return false;
@ -97,6 +99,12 @@ void ADC_Disable()
}
void ADC_SetPin(uint8_t pin_num)
{
RegEdit_ClearRegister((void *) &ADC0.MUXPOS);
RegEdit_SetNum((void *) &ADC0.MUXPOS, pin_num);
}
uint16_t ADC_ReadValue_Impl(uint8_t pin_num)
{
RegEdit_SetNum((void *) &ADC0.COMMAND, ADC_STCONV_bm);

View File

@ -65,4 +65,11 @@ extern uint16_t (*ADC_ReadValue)(uint8_t pin_num);
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.
*/
void ADC_SetPin(uint8_t pin_num);
#endif //ADC_H

View File

@ -182,6 +182,19 @@ TEST(test_ADC, ADC_DisablePasses)
ADC_Disable();
}
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);
}
static uint16_t ADC_ReadValueFake(uint8_t pin_num)