Added function to select the ADC0.MUXPOS pins.
This commit is contained in:
parent
fae7509dba
commit
9e750af5bf
|
@ -13,11 +13,13 @@
|
||||||
#include "RegEdit.h"
|
#include "RegEdit.h"
|
||||||
#include "avr/io.h"
|
#include "avr/io.h"
|
||||||
|
|
||||||
|
#define MAX_PIN_NUM 7
|
||||||
|
|
||||||
static uint8_t porta_out;
|
static uint8_t porta_out;
|
||||||
static uint8_t porta_dir;
|
static uint8_t porta_dir;
|
||||||
|
|
||||||
static bool IsInvalidPin(uint8_t pin_num){
|
static bool IsInvalidPin(uint8_t pin_num){
|
||||||
if(pin_num > 7){
|
if(pin_num > MAX_PIN_NUM){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
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)
|
uint16_t ADC_ReadValue_Impl(uint8_t pin_num)
|
||||||
{
|
{
|
||||||
RegEdit_SetNum((void *) &ADC0.COMMAND, ADC_STCONV_bm);
|
RegEdit_SetNum((void *) &ADC0.COMMAND, ADC_STCONV_bm);
|
||||||
|
|
|
@ -65,4 +65,11 @@ extern uint16_t (*ADC_ReadValue)(uint8_t pin_num);
|
||||||
void ADC_Setup(void);
|
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
|
#endif //ADC_H
|
||||||
|
|
|
@ -182,6 +182,19 @@ TEST(test_ADC, ADC_DisablePasses)
|
||||||
ADC_Disable();
|
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)
|
static uint16_t ADC_ReadValueFake(uint8_t pin_num)
|
||||||
|
|
Loading…
Reference in New Issue