/* Copyright 2022, Savanni D'Gerinel This file is part of Savanni's AVR library. Lumeto 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. Lumeto 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 Lumeto. If not, see . */ #ifndef __BASE_H__ #define __BASE_H__ #include #include #define LINE_OUT 1 #define LINE_IN 0 typedef struct GPIO { volatile uint8_t *ddr; volatile uint8_t *port; volatile uint8_t *pin; uint8_t addr; } gpio_t; /* #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 } */ inline void set_line_direction(gpio_t *line, int direction) { if (direction == LINE_OUT) { *(line->ddr) |= _BV(line->addr); } else { *(line->ddr) &= ~(_BV(line->addr)); } } inline void set_line(gpio_t *line) { *(line->port) |= _BV(line->addr); } inline void clear_line(gpio_t *line) { *(line->port) &= ~(_BV(line->addr)); } inline int read_line(gpio_t *line) { return (*(line->port) & _BV(line->addr)) > 0; } 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); #endif