Some more changes.

This commit is contained in:
Marco 2022-05-11 22:21:21 +02:00
parent 9cb9d7f3a8
commit 4d385e20f4
6 changed files with 83 additions and 0 deletions

BIN
docs/feather_pinout.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 277 KiB

BIN
docs/feather_schematic.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

3
src/include/timer.h Normal file
View File

@ -0,0 +1,3 @@
void initCtcTimer0(void);
void initOverflowTimer0(void);
void initOverflowTimer1(void);

5
src/include/uart.h Normal file
View File

@ -0,0 +1,5 @@
#include <stdio.h>
void uart_init(unsigned int baud);
void uart_sendByte(uint8_t byte);
int uart_printf(char var, FILE *stream);

37
src/timer.c Normal file
View File

@ -0,0 +1,37 @@
#include <avr/io.h>
#include "include/timer.h"
void initCtcTimer0(void)
{
/* Initialize counter 0 */
TCNT0 = 0;
/* Enable Counter0 Compare Match A Interrupt */
TIMSK0 |= (1 << OCIE0A);
/* Select clock. Prescaler of 1024 */
TCCR0B |= (1 << CS02) | (1 << CS00);
/* Use CTC Mode */
TCCR0A |= (1 << WGM01);
/*
* OCR0A contains TOP value for counter:
*/
OCR0A = 78;
}
void initOverflowTimer0(void)
{
/* Prescaler = 0 */
TCCR0B |= (1<<CS00);
/* Enable Timer Overflow Interrupt */
TIMSK0 |= (1<<TOIE0);
}
void initOverflowTimer1(void)
{
TCCR1B |= (1<<CS11);
TIMSK1 |= (1<<TOIE1);
}

38
src/uart.c Normal file
View File

@ -0,0 +1,38 @@
#include <avr/io.h>
#include "include/uart.h"
static FILE stream = FDEV_SETUP_STREAM(uart_printf, NULL, _FDEV_SETUP_WRITE);
void uart_init(unsigned int baud)
{
stdout = &stream;
/* Set baud rate */
UBRR1H = (unsigned char)(baud>>8);
UBRR1L = (unsigned char)baud;
/* Enable receiver and transmitter */
UCSR1B = (1<<RXEN1)|(1<<TXEN1);
/* Set frame format */
UCSR1C |= (3<<UCSZ10); // 8 data bits
// UCSR1C &= ~(1<<USBS1); // 1 stop bit
}
void uart_sendByte(uint8_t byte)
{
/* Wait for empty transmit buffer */
while (!(UCSR1A & (1<<UDRE1)))
{
}
/* Put data into buffer, sends the data */
UDR1 = byte;
}
int uart_printf(char var, FILE *stream)
{
uart_sendByte(var);
return 0;
}