Compare commits

..

No commits in common. "5178c69a14d1e6028c6670ff2c95cc606742469f" and "e769b0035460ef6399840e3a0ad06af09047fa2c" have entirely different histories.

4 changed files with 87 additions and 20 deletions

71
inc/RegEdit.h Normal file
View file

@ -0,0 +1,71 @@
/**
* @brief Module/Interface for editing AVR registers
* @details This file is an interface to AVR registers or the avr/io.h
* @author Jake G
* @date 2024
* @copyright None
* @file RegEdit.h
*/
#ifndef REGEDIT_H
#define REGEDIT_H
#include <stdint.h>
#include <stdbool.h>
/**
* @brief Sets the value of the register to 0xFF.
* @param reg A pointer to a register
*/
void RegEdit_SetRegister(void *reg);
/**
* @brief Sets the value of the register to 0x00.
* @param reg A pointer to a register
*/
void RegEdit_ClearRegister(void *reg);
/**
* @brief Sets a single bit in the register.
* @param reg A pointer to a register
* @param The bit's index or number in the register
*/
void RegEdit_SetBit(void *reg, uint8_t bit_num);
/**
* @brief Clears a single bit in the register.
* @param reg A pointer to a register
* @param The bit's index or number in the register
*/
void RegEdit_ClearBit(void *reg, uint8_t bit_num);
/**
* @brief Checks if a single bit is set in the register.
* @param reg A pointer to a register
* @param The bit's index or number in the register
*/
bool RegEdit_IsBitSet(void *reg, uint8_t bit_num);
/**
* @brief Preforms logical OR Equals with the passed num.
* @param reg A pointer to a register
* @param The bit's index or number in the register
*/
void RegEdit_OR_Num(void *reg, uint8_t num);
/**
* @brief Preforms logical AND Equals with the passed num.
* @param reg A pointer to a register
* @param The bit's index or number in the register
*/
void RegEdit_AND_Num(void *reg, uint8_t num);
/**
* @brief Sets the register to the passed number value.
* @param reg A pointer to a register
* @param The bit's index or number in the register
*/
void RegEdit_SetNum(void *reg, uint8_t num);
#endif //REGEDIT_H

View file

@ -47,7 +47,7 @@ void ADC_Setup(void)
void ADC_PowerOn(void) void ADC_PowerOn(void)
{ {
RegEdit_u32_SetBit((void *)&ADC1->CTLR2, ADC_ADON); RegEdit_SetBit((void *)&ADC1->CTLR2, ADC_ADON);
} }
void ADC_Init(uint8_t pin_num) void ADC_Init(uint8_t pin_num)

View file

@ -11,7 +11,6 @@
#define ADC_H #define ADC_H
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h>
#include <stdint.h> #include <stdint.h>
/** /**

View file

@ -1,6 +1,6 @@
/* /*
* Author: Jake G * Author: Jake G
* Date: 2025 * Date: 2024
* filename: test_ADC.c * filename: test_ADC.c
* description: module_purpose * description: module_purpose
*/ */
@ -15,17 +15,15 @@ extern "C"
#include "ch32v003hw.h" #include "ch32v003hw.h"
} }
TEST_GROUP(test_ADC) TEST_GROUP(test_ADC){
{
void setup(){ void setup(){
} } void teardown(){
void teardown()
{
mock().checkExpectations(); mock().checkExpectations();
mock().clear(); mock().clear();
} }
}; }
;
TEST(test_ADC, FirstTest) TEST(test_ADC, FirstTest)
{ {
@ -35,7 +33,7 @@ TEST(test_ADC, FirstTest)
TEST(test_ADC, ADC_PowerOnTest) TEST(test_ADC, ADC_PowerOnTest)
{ {
// The ADCON bit should be high in the ADC_CTRL2 register. // The ADCON bit should be high in the ADC_CTRL2 register.
mock().expectOneCall("RegEdit_u32_SetBit").withPointerParameter("reg", (void *)&ADC1->CTLR2).withUnsignedIntParameter("bit_num", ADC_ADON); mock().expectOneCall("RegEdit_SetBit").withPointerParameter("reg", (void *)&ADC1->CTLR2).withUnsignedIntParameter("bit_num", ADC_ADON);
ADC_PowerOn(); ADC_PowerOn();
} }
@ -197,19 +195,18 @@ static uint16_t ADC_ReadValueFake(uint8_t pin_num)
return 512; return 512;
} }
TEST_GROUP(tg_ADCRead){ TEST_GROUP(test_ADCRead){
void setup(){ void setup(){
UT_PTR_SET(ADC_ReadValue, ADC_ReadValueFake); UT_PTR_SET(ADC_ReadValue, ADC_ReadValueFake);
} }
void teardown() void teardown()
{ {
mock().checkExpectations(); }
mock().clear(); }
} ;
};
TEST(tg_ADCRead, FunctionPointerSwapWorks) TEST(test_ADCRead, FunctionPointerSwapWorks)
{ {
uint16_t value = ADC_ReadValue(0); uint16_t value = ADC_ReadValue(0);