2022-04-17 04:43:50 +00:00
|
|
|
#ifndef __BASE_H__
|
|
|
|
#define __BASE_H__
|
|
|
|
|
2022-06-26 15:38:20 +00:00
|
|
|
#include <avr/io.h>
|
|
|
|
#include <avr/delay.h>
|
|
|
|
|
2022-06-20 18:52:29 +00:00
|
|
|
#define LINE_OUT 1
|
|
|
|
#define LINE_IN 0
|
2022-06-18 03:06:10 +00:00
|
|
|
|
2022-06-20 18:52:29 +00:00
|
|
|
typedef struct GPIO {
|
2022-06-18 03:06:10 +00:00
|
|
|
volatile uint8_t *ddr;
|
2022-04-17 04:43:50 +00:00
|
|
|
volatile uint8_t *port;
|
2022-06-20 18:52:29 +00:00
|
|
|
volatile uint8_t *pin;
|
2022-06-18 03:06:10 +00:00
|
|
|
uint8_t addr;
|
2022-06-20 18:52:29 +00:00
|
|
|
} gpio_t;
|
2022-04-17 04:43:50 +00:00
|
|
|
|
2022-06-18 03:06:10 +00:00
|
|
|
/*
|
2022-06-20 18:52:29 +00:00
|
|
|
#define GPIOA(addr) (gpio_t){ .ddr = &DDRA, .port = &PORTA, .addr = addr }
|
|
|
|
#define GPIOB(addr) (gpio_t){ .ddr = &DDRB, .port = &PORTB, .addr = addr }
|
|
|
|
#define GPIOC(addr) (gpio_t){ .ddr = &DDRC, .port = &PORTC, .addr = addr }
|
|
|
|
#define GPIOD(addr) (gpio_t){ .ddr = &DDRD, .port = &PORTD, .addr = addr }
|
2022-06-18 03:06:10 +00:00
|
|
|
*/
|
|
|
|
|
2022-06-20 18:52:29 +00:00
|
|
|
inline void set_line_direction(gpio_t *line, int direction) {
|
|
|
|
if (direction == LINE_OUT) {
|
|
|
|
*(line->ddr) |= _BV(line->addr);
|
2022-06-18 03:06:10 +00:00
|
|
|
} else {
|
2022-06-20 18:52:29 +00:00
|
|
|
*(line->ddr) &= ~(_BV(line->addr));
|
2022-06-18 03:06:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-20 18:52:29 +00:00
|
|
|
inline void set_line(gpio_t *line) {
|
|
|
|
*(line->port) |= _BV(line->addr);
|
2022-04-17 04:43:50 +00:00
|
|
|
}
|
|
|
|
|
2022-06-20 18:52:29 +00:00
|
|
|
inline void clear_line(gpio_t *line) {
|
|
|
|
*(line->port) &= ~(_BV(line->addr));
|
2022-04-17 04:43:50 +00:00
|
|
|
}
|
|
|
|
|
2022-06-20 18:52:29 +00:00
|
|
|
inline int read_line(gpio_t *line) {
|
|
|
|
return (*(line->port) & _BV(line->addr)) > 0;
|
2022-06-20 15:40:55 +00:00
|
|
|
}
|
|
|
|
|
2022-05-07 23:49:54 +00:00
|
|
|
typedef struct RNG {
|
|
|
|
uint8_t mod;
|
|
|
|
int8_t a;
|
|
|
|
int8_t c;
|
|
|
|
uint8_t seed;
|
|
|
|
} rng_t;
|
|
|
|
|
|
|
|
rng_t rng_new(uint8_t seed);
|
|
|
|
|
|
|
|
uint8_t rng_sample(rng_t *state);
|
2022-04-17 04:43:50 +00:00
|
|
|
|
|
|
|
#endif
|