Decouple hardware specific code from generic, agnostic code

This commit is contained in:
Allen Hill
2026-06-23 17:20:59 -07:00
parent fb130559e2
commit 0b0c9335f9
24 changed files with 768 additions and 910 deletions
@@ -0,0 +1,62 @@
/*
AVCLAN-Mockingboard
Copyright (C) 2015 Allen Hill <allenofthehills@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// ATtiny3216 board bring-up: main-clock prescaler + GPIO config for pins not
// owned by a peripheral's own init.
#include <avr/interrupt.h>
#include <avr/io.h>
#include <avr/xmega.h> // _PROTECTED_WRITE
#include "board.h"
void board_init(void) {
// Main clock prescale (CLK_PRESCALE / CLK_PRESCALE_DIV come from the build).
_PROTECTED_WRITE(CLKCTRL.MCLKCTRLB, (CLK_PRESCALE | CLK_PRESCALE_DIV));
// Set pins PC2-3, PB0,3-5 as inputs
PORTC.DIRCLR = (PIN2_bm | // Unconnected
PIN3_bm); // CTS
PORTB.DIRCLR = (PIN0_bm | // Unconnected
PIN3_bm | // IGN_SENSE
PIN4_bm | // Unused, but connected to WOC (PC0)
PIN5_bm); // Unused, but connected to WOD (PC1)
// Enable pull-up resistor and disable input buffer (reduces any EM caused
// pin toggling and saves power) for unused and unconnected pins
PORTC.PIN2CTRL = PORT_PULLUPEN_bm | PORT_ISC_INPUT_DISABLE_gc;
PORTB.PIN0CTRL = PORT_PULLUPEN_bm | PORT_ISC_INPUT_DISABLE_gc;
// TODO: Remove once IGN_SENSE hardware is fixed
PORTB.DIRSET = PIN3_bm;
PORTB.OUTSET = PIN3_bm;
// Output only pins: PA3-5, PB1-2,4-5; PC0-1
// TODO: TxD (PA1), RTS (PA3) is output only, test if RxD needs the input
// buffer or if the UART peripheral bypasses it
PORTA.PIN3CTRL = PORT_ISC_INPUT_DISABLE_gc; // RTS
PORTA.PIN4CTRL = PORT_ISC_INPUT_DISABLE_gc; // WOA
PORTA.PIN5CTRL = PORT_ISC_INPUT_DISABLE_gc; // WOB
PORTB.PIN1CTRL = PORT_ISC_INPUT_DISABLE_gc; // MIC_CONTROL
PORTB.PIN4CTRL = PORT_ISC_INPUT_DISABLE_gc; // non-driving WOC
PORTB.PIN5CTRL = PORT_ISC_INPUT_DISABLE_gc; // non-driving WOD
PORTC.PIN0CTRL = PORT_ISC_INPUT_DISABLE_gc; // WOC
PORTC.PIN1CTRL = PORT_ISC_INPUT_DISABLE_gc; // WOD
}
void board_interruptsEnable(void) { sei(); }