Compare commits
No commits in common. "38dea7ead4e1747034a96505e8281e31dbd8c65f" and "968570e898415205f379c54867685d45510c996f" have entirely different histories.
38dea7ead4
...
968570e898
3 changed files with 18 additions and 44 deletions
|
@ -1,29 +1,8 @@
|
||||||
/*
|
/*
|
||||||
* Author: Jake Goodwin
|
* Author: username
|
||||||
* Date: 2025
|
* Date: 2024
|
||||||
* filename: ADC.c
|
* filename: ADC.c
|
||||||
* description:
|
* description: module_purpose
|
||||||
*/
|
|
||||||
|
|
||||||
/*DEVNOTES:
|
|
||||||
* The CH32v003 micro-controllers have 8channels for the ADC that are
|
|
||||||
* external and 2 internal channels.
|
|
||||||
*
|
|
||||||
* The channels/inputs are labeled as AIN0-AIN7
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*CH32v003 ADC TO PINs:
|
|
||||||
* A0 --> PA2
|
|
||||||
* A1 --> PA1
|
|
||||||
* A2 --> PC2
|
|
||||||
* A3 --> PD2
|
|
||||||
* A4 --> PD3
|
|
||||||
* A5 --> PD5
|
|
||||||
* A6 --> PD6
|
|
||||||
* A7 --> PD4
|
|
||||||
*
|
|
||||||
* Because they don't exactly match up, I'll need to write up my own
|
|
||||||
* way to do the mapping.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ADC.h"
|
#include "ADC.h"
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
/**
|
/**
|
||||||
* @brief Interface to the AVR ADC hardware.
|
* @brief Interface to the AVR ADC hardware.
|
||||||
* @details This file is...
|
* @details This file is...
|
||||||
* @author Jake Goodwin
|
* @author Jake G
|
||||||
* @date 2025
|
* @date 2024
|
||||||
* @copyright None
|
* @copyright None
|
||||||
* @file ADC.h
|
* @file ADC.h
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -9,9 +9,13 @@
|
||||||
#include "CppUTestExt/MockSupport.h"
|
#include "CppUTestExt/MockSupport.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
//This define allows us to dircetly include the device header without error.
|
||||||
|
#define _AVR_IO_H_
|
||||||
|
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#include "ch32v003hw.h"
|
#include <iotn404.h> //ATtiny404 header fille.
|
||||||
#include "ADC.h"
|
#include "ADC.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,8 +40,6 @@ TEST(test_ADC, FirstTest)
|
||||||
|
|
||||||
TEST(test_ADC, ADC_SetupSetsRegisters)
|
TEST(test_ADC, ADC_SetupSetsRegisters)
|
||||||
{
|
{
|
||||||
|
|
||||||
/*
|
|
||||||
//Clears control register A for ADC0
|
//Clears control register A for ADC0
|
||||||
mock().expectOneCall("RegEdit_SetNum")
|
mock().expectOneCall("RegEdit_SetNum")
|
||||||
.withPointerParameter("reg", (void *) &ADC0.CTRLA)
|
.withPointerParameter("reg", (void *) &ADC0.CTRLA)
|
||||||
|
@ -67,14 +69,12 @@ TEST(test_ADC, ADC_SetupSetsRegisters)
|
||||||
mock().expectOneCall("RegEdit_SetBit")
|
mock().expectOneCall("RegEdit_SetBit")
|
||||||
.withPointerParameter("reg", (void *) &ADC0.CTRLD)
|
.withPointerParameter("reg", (void *) &ADC0.CTRLD)
|
||||||
.withUnsignedIntParameter("bit_num", 4);
|
.withUnsignedIntParameter("bit_num", 4);
|
||||||
|
|
||||||
*/
|
|
||||||
ADC_Setup();
|
ADC_Setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_ADC, ADC_InitPortAPin7UsesCorrectRegisters)
|
TEST(test_ADC, ADC_InitPortAPin7UsesCorrectRegisters)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
//Check for setting the direction to input.
|
//Check for setting the direction to input.
|
||||||
mock().expectOneCall("RegEdit_ClearBit")
|
mock().expectOneCall("RegEdit_ClearBit")
|
||||||
.withPointerParameter("reg", (void *) &PORTA.DIR)
|
.withPointerParameter("reg", (void *) &PORTA.DIR)
|
||||||
|
@ -91,13 +91,13 @@ TEST(test_ADC, ADC_InitPortAPin7UsesCorrectRegisters)
|
||||||
.withPointerParameter("reg", (void *) &PORTA.PIN7CTRL)
|
.withPointerParameter("reg", (void *) &PORTA.PIN7CTRL)
|
||||||
.withUnsignedIntParameter("bit_num", PORT_ISC_INPUT_DISABLE_gc);
|
.withUnsignedIntParameter("bit_num", PORT_ISC_INPUT_DISABLE_gc);
|
||||||
|
|
||||||
*/
|
|
||||||
ADC_Init(7);
|
ADC_Init(7);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_ADC, ADC_InitPortAPin0UsesCorrectRegisters)
|
TEST(test_ADC, ADC_InitPortAPin0UsesCorrectRegisters)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
//Check for setting the direction to input.
|
//Check for setting the direction to input.
|
||||||
mock().expectOneCall("RegEdit_ClearBit")
|
mock().expectOneCall("RegEdit_ClearBit")
|
||||||
.withPointerParameter("reg", (void *) &PORTA.DIR)
|
.withPointerParameter("reg", (void *) &PORTA.DIR)
|
||||||
|
@ -113,43 +113,39 @@ TEST(test_ADC, ADC_InitPortAPin0UsesCorrectRegisters)
|
||||||
mock().expectOneCall("RegEdit_SetBit")
|
mock().expectOneCall("RegEdit_SetBit")
|
||||||
.withPointerParameter("reg", (void *) &PORTA.PIN0CTRL)
|
.withPointerParameter("reg", (void *) &PORTA.PIN0CTRL)
|
||||||
.withUnsignedIntParameter("bit_num", PORT_ISC_INPUT_DISABLE_gc);
|
.withUnsignedIntParameter("bit_num", PORT_ISC_INPUT_DISABLE_gc);
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
ADC_Init(0);
|
ADC_Init(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_ADC, ADC_InitDoesNothingOnHighPinNumbers)
|
TEST(test_ADC, ADC_InitDoesNothingOnHighPinNumbers)
|
||||||
{
|
{
|
||||||
//mock().expectNoCall("RegEdit_SetBit");
|
mock().expectNoCall("RegEdit_SetBit");
|
||||||
ADC_Init(8);
|
ADC_Init(8);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_ADC, ADC_EnablePasses)
|
TEST(test_ADC, ADC_EnablePasses)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
mock().expectOneCall("RegEdit_SetBit")
|
mock().expectOneCall("RegEdit_SetBit")
|
||||||
.withPointerParameter("reg", (void *) &ADC0.CTRLA)
|
.withPointerParameter("reg", (void *) &ADC0.CTRLA)
|
||||||
.withUnsignedIntParameter("bit_num", 0);
|
.withUnsignedIntParameter("bit_num", 0);
|
||||||
|
|
||||||
*/
|
|
||||||
ADC_Enable();
|
ADC_Enable();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_ADC, ADC_DisablePasses)
|
TEST(test_ADC, ADC_DisablePasses)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
mock().expectOneCall("RegEdit_ClearBit")
|
mock().expectOneCall("RegEdit_ClearBit")
|
||||||
.withPointerParameter("reg", (void *) &ADC0.CTRLA)
|
.withPointerParameter("reg", (void *) &ADC0.CTRLA)
|
||||||
.withUnsignedIntParameter("bit_num", 0);
|
.withUnsignedIntParameter("bit_num", 0);
|
||||||
*/
|
|
||||||
ADC_Disable();
|
ADC_Disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_ADC, ADC_SetPinSetsRightRegisters)
|
TEST(test_ADC, ADC_SetPinSetsRightRegisters)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
//It clears existing MUXPOS register values.
|
//It clears existing MUXPOS register values.
|
||||||
mock().expectOneCall("RegEdit_ClearRegister")
|
mock().expectOneCall("RegEdit_ClearRegister")
|
||||||
.withPointerParameter("reg", (void *) &ADC0.MUXPOS);
|
.withPointerParameter("reg", (void *) &ADC0.MUXPOS);
|
||||||
|
@ -158,8 +154,7 @@ TEST(test_ADC, ADC_SetPinSetsRightRegisters)
|
||||||
mock().expectOneCall("RegEdit_SetNum")
|
mock().expectOneCall("RegEdit_SetNum")
|
||||||
.withPointerParameter("reg", (void *) &ADC0.MUXPOS)
|
.withPointerParameter("reg", (void *) &ADC0.MUXPOS)
|
||||||
.withUnsignedIntParameter("num", 4);
|
.withUnsignedIntParameter("num", 4);
|
||||||
|
|
||||||
*/
|
|
||||||
ADC_SetPin(4);
|
ADC_SetPin(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue