fix of port storage

This commit is contained in:
jakeg00dwin 2024-07-26 18:19:36 -07:00
parent 6ecbe2f48a
commit 8117d3f890
1 changed files with 10 additions and 5 deletions

View File

@ -5,6 +5,10 @@
* description: module_purpose
*/
#ifndef __AVR_ATtiny404__
#define __AVR_ATtiny404__
#endif
#include "ADC.h"
#include "RegEdit.h"
#include "avr/io.h"
@ -22,12 +26,13 @@ static bool IsInvalidPin(uint8_t pin_num){
void ADC_Init(uint8_t pin_num)
{
//Save the porta status.
porta_out = PORTA.OUT;
porta_dir = PORTA.DIR;
if(IsInvalidPin(pin_num)){return;}
//Save the porta status.
//porta_out = PORTA.OUT;
//porta_dir = PORTA.DIR;
//set the direction to input
RegEdit_SetBit((void *) &PORTA.DIRCLR, pin_num);
@ -78,8 +83,8 @@ void ADC_Disable()
RegEdit_ClearBit((void *) &ADC0.CTRLA, 0);
//Restore the port registers
PORTA.OUT = porta_out;
PORTA.DIR = porta_dir;
RegEdit_SetNum((void *) &PORTA.OUT, porta_out);
RegEdit_SetNum((void *) &PORTA.DIR, porta_dir);
}