some i/o fixes
This commit is contained in:
@@ -152,7 +152,7 @@ void aaio_led_toggle() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* set the internal LED */
|
/* set the internal LED */
|
||||||
void aaio_led_set(uint8_t v) {
|
void aaio_led_set(register uint8_t v) {
|
||||||
if(v == 0) {
|
if(v == 0) {
|
||||||
AAIO_LED_PORT &= ~(1 << AAIO_LED_PIN);
|
AAIO_LED_PORT &= ~(1 << AAIO_LED_PIN);
|
||||||
} else {
|
} else {
|
||||||
@@ -182,7 +182,7 @@ void aaio_uart_init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* put a character into the bus */
|
/* put a character into the bus */
|
||||||
int aaio_uart_putchar(char c, FILE *stream) {
|
int aaio_uart_putchar(register char c, FILE *stream) {
|
||||||
if(c == '\n') aaio_uart_putchar('\r', stream);
|
if(c == '\n') aaio_uart_putchar('\r', stream);
|
||||||
loop_until_bit_is_set(UCSR0A, UDRE0);
|
loop_until_bit_is_set(UCSR0A, UDRE0);
|
||||||
UDR0 = c;
|
UDR0 = c;
|
||||||
@@ -195,10 +195,28 @@ int aaio_uart_getchar(FILE *stream) {
|
|||||||
return (UDR0);
|
return (UDR0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* put a null-terminated string into the bus */
|
||||||
|
void aaio_uart_puts(char *buf) {
|
||||||
|
while(*buf)
|
||||||
|
aaio_uart_putchar(*(buf++), NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* print a number into the bus */
|
||||||
|
void aaio_uart_printnum(register unsigned int value) {
|
||||||
|
register uint8_t d;
|
||||||
|
register uint32_t threshold = 1000000000;
|
||||||
|
for(;threshold > 0;threshold /= 10) {
|
||||||
|
if(value > threshold) {
|
||||||
|
d = (value / threshold) % 10;
|
||||||
|
aaio_uart_putchar('0' + d, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* get a string of length len from the bus, optionally echoing it back */
|
/* get a string of length len from the bus, optionally echoing it back */
|
||||||
int aaio_uart_gets(char *buf, unsigned int len, char echo) {
|
int aaio_uart_gets(char *buf, register unsigned int len, register char echo) {
|
||||||
unsigned int i;
|
register unsigned int i;
|
||||||
char c;
|
register char c;
|
||||||
do {
|
do {
|
||||||
for(i = 0; i < len - 1; i++) {
|
for(i = 0; i < len - 1; i++) {
|
||||||
c = (char) aaio_uart_getchar(NULL);
|
c = (char) aaio_uart_getchar(NULL);
|
||||||
@@ -235,7 +253,7 @@ void aaio_uart_redirect_stdout() {
|
|||||||
/* scan the keyboard and return the associated value */
|
/* scan the keyboard and return the associated value */
|
||||||
/* the definition must be stored in PROGMEM */
|
/* the definition must be stored in PROGMEM */
|
||||||
uint8_t aaio_scankey(const uint8_t keypad_def[4][4]) {
|
uint8_t aaio_scankey(const uint8_t keypad_def[4][4]) {
|
||||||
uint8_t row, col, dirmask;
|
register uint8_t row, col, dirmask;
|
||||||
for(col = 0; col < 4; col++) {
|
for(col = 0; col < 4; col++) {
|
||||||
AAIO_KEYPAD_DDR = dirmask = 1 << (col + 4);
|
AAIO_KEYPAD_DDR = dirmask = 1 << (col + 4);
|
||||||
AAIO_KEYPAD_PORT = 0xf & ~dirmask;
|
AAIO_KEYPAD_PORT = 0xf & ~dirmask;
|
||||||
@@ -273,7 +291,7 @@ static struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* send data to the LCD (in data or command mode) */
|
/* send data to the LCD (in data or command mode) */
|
||||||
static void _aaio_lcd_write(uint8_t byte, uint8_t is_data) {
|
static void _aaio_lcd_write(register uint8_t byte, register uint8_t is_data) {
|
||||||
register uint8_t i;
|
register uint8_t i;
|
||||||
AAIO_LCD_PORT &= ~(1 << AAIO_LCD_SCE); /* enable the controller */
|
AAIO_LCD_PORT &= ~(1 << AAIO_LCD_SCE); /* enable the controller */
|
||||||
if(is_data)
|
if(is_data)
|
||||||
@@ -293,11 +311,11 @@ static void _aaio_lcd_write(uint8_t byte, uint8_t is_data) {
|
|||||||
AAIO_LCD_PORT |= (1 << AAIO_LCD_SCE); /* disable the controller */
|
AAIO_LCD_PORT |= (1 << AAIO_LCD_SCE); /* disable the controller */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _aaio_lcd_write_cmd(uint8_t cmd) {
|
static void _aaio_lcd_write_cmd(register uint8_t cmd) {
|
||||||
_aaio_lcd_write(cmd, 0);
|
_aaio_lcd_write(cmd, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _aaio_lcd_write_data(uint8_t data) {
|
static void _aaio_lcd_write_data(register uint8_t data) {
|
||||||
_aaio_lcd_write(data, 1);
|
_aaio_lcd_write(data, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -351,19 +369,19 @@ void aaio_lcd_clear(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* power the LCD on/off */
|
/* power the LCD on/off */
|
||||||
void aaio_lcd_power(uint8_t on) {
|
void aaio_lcd_power(register uint8_t on) {
|
||||||
_aaio_lcd_write_cmd(on ? 0x20 : 0x24);
|
_aaio_lcd_write_cmd(on ? 0x20 : 0x24);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set a pixel */
|
/* set a pixel */
|
||||||
void aaio_lcd_set_pixel(uint8_t x, uint8_t y, uint8_t value) {
|
void aaio_lcd_set_pixel(register uint8_t x, register uint8_t y, register uint8_t value) {
|
||||||
uint8_t *byte = &_aaio_lcd.screen[(y >> 3) * 84 + x];
|
uint8_t *byte = &_aaio_lcd.screen[(y >> 3) * 84 + x];
|
||||||
if(value) *byte |= (1 << (y & 7));
|
if(value) *byte |= (1 << (y & 7));
|
||||||
else *byte &= ~(1 << (y & 7));
|
else *byte &= ~(1 << (y & 7));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write an ASCII character */
|
/* write an ASCII character */
|
||||||
void aaio_lcd_write_char(char code, uint8_t scale) {
|
void aaio_lcd_write_char(register char code, register uint8_t scale) {
|
||||||
register uint8_t x, y;
|
register uint8_t x, y;
|
||||||
for(x = 0; x < 5*scale; x++)
|
for(x = 0; x < 5*scale; x++)
|
||||||
for(y = 0; y < 7*scale; y++)
|
for(y = 0; y < 7*scale; y++)
|
||||||
@@ -382,11 +400,11 @@ void aaio_lcd_write_char(char code, uint8_t scale) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void aaio_lcd_write_string(const char *str, uint8_t scale) {
|
void aaio_lcd_write_string(const char *str, register uint8_t scale) {
|
||||||
while(*str) aaio_lcd_write_char(*str++, scale);
|
while(*str) aaio_lcd_write_char(*str++, scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
void aaio_lcd_set_cursor(uint8_t x, uint8_t y) {
|
void aaio_lcd_set_cursor(register uint8_t x, register uint8_t y) {
|
||||||
_aaio_lcd.cursor_x = x;
|
_aaio_lcd.cursor_x = x;
|
||||||
_aaio_lcd.cursor_y = y;
|
_aaio_lcd.cursor_y = y;
|
||||||
}
|
}
|
||||||
@@ -402,4 +420,24 @@ void aaio_lcd_render(void) {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* PRNG feature */
|
||||||
|
|
||||||
|
#ifdef AAIO_FEATURE_RNG
|
||||||
|
|
||||||
|
static uint32_t _aaio_rng_state;
|
||||||
|
|
||||||
|
void aaio_srand() {
|
||||||
|
_aaio_rng_state = 0xdeadbeef;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t aaio_rand() {
|
||||||
|
register uint32_t x = _aaio_rng_state;
|
||||||
|
x ^= x << 13;
|
||||||
|
x ^= x >> 17;
|
||||||
|
x ^= x << 5;
|
||||||
|
return _aaio_rng_state = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user