Date:2011-06-09 19:02:26 (9 years 2 months ago)
Author:Werner Almesberger
Commit:ec7c93789ad1bc71b9c7f2539f112891bbf1588e
Message:atusb/fw/: added "lazy enabling" of UART-SPI after ATUSB_GPIO

- spi.h (spi_off), spi.c: disable the UART
- spi.c (spi_initialized, spi_begin, spi_init): initialize the UART
if necessary
- board_app.c (gpio): call spi_off to disable the UART instead of
open-coding the operation
- board_app.c (gpio): don't explicitly re-enable the UART but defer it
to the next communication
Files: atusb/fw/board_app.c (2 diffs)
atusb/fw/spi.c (3 diffs)
atusb/fw/spi.h (1 diff)

Change Details

atusb/fw/board_app.c
9494    }
9595
9696    /* disable the UART so that we can meddle with these pins as well. */
97    UCSR1B = 0;
97    spi_off();
9898    _delay_ms(1);
9999
100100    switch (port) {
...... 
115115        break;
116116    }
117117
118    spi_init();
119
120118    return 1;
121119}
atusb/fw/spi.c
1919#include "spi.h"
2020
2121
22static int spi_initialized = 0;
23
24
2225void spi_begin(void)
2326{
27    if (!spi_initialized)
28        spi_init();
2429    CLR(nSS);
2530}
2631
...... 
4146}
4247
4348
49void spi_off(void)
50{
51    spi_initialized = 0;
52    UCSR1B = 0;
53}
54
55
4456void spi_init(void)
4557{
4658    SET(nSS);
...... 
5567    UCSR1B = 1 << RXEN1 | 1 << TXEN1;
5668            /* enable receiver and transmitter */
5769    UBRR1 = 0; /* reconfirm the bit rate */
70
71    spi_initialized = 1;
5872}
atusb/fw/spi.h
1919void spi_begin(void);
2020uint8_t spi_io(uint8_t v);
2121void spi_end(void);
22void spi_off(void);
2223void spi_init(void);
2324
2425#define spi_send(v) (void) spi_io(v)

Archive Download the corresponding diff file



interactive