Compare commits

...

3 commits

4 changed files with 20 additions and 87 deletions

View file

@ -1,71 +0,0 @@
/**
* @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)
{
RegEdit_SetBit((void *)&ADC1->CTLR2, ADC_ADON);
RegEdit_u32_SetBit((void *)&ADC1->CTLR2, ADC_ADON);
}
void ADC_Init(uint8_t pin_num)

View file

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

View file

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