Compare commits
2 commits
968570e898
...
38dea7ead4
Author | SHA1 | Date | |
---|---|---|---|
38dea7ead4 | |||
a076ab8b77 |
3 changed files with 44 additions and 18 deletions
|
@ -1,8 +1,29 @@
|
||||||
/*
|
/*
|
||||||
* Author: username
|
* Author: Jake Goodwin
|
||||||
* Date: 2024
|
* Date: 2025
|
||||||
* filename: ADC.c
|
* filename: ADC.c
|
||||||
* description: module_purpose
|
* description:
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*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 G
|
* @author Jake Goodwin
|
||||||
* @date 2024
|
* @date 2025
|
||||||
* @copyright None
|
* @copyright None
|
||||||
* @file ADC.h
|
* @file ADC.h
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -9,13 +9,9 @@
|
||||||
#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 <iotn404.h> //ATtiny404 header fille.
|
#include "ch32v003hw.h"
|
||||||
#include "ADC.h"
|
#include "ADC.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +36,8 @@ 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)
|
||||||
|
@ -69,12 +67,14 @@ 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,39 +113,43 @@ 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);
|
||||||
|
@ -154,7 +158,8 @@ 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