60b4d3b3a1785c9a9adfa4f3c9b18741d86508bf
1 /**************************************************************************/
4 @author K. Townsend (microBuilder.eu)
10 Software License Agreement (BSD License)
12 Copyright (c) 2010, microBuilder SARL
15 Redistribution and use in source and binary forms, with or without
16 modification, are permitted provided that the following conditions are met:
17 1. Redistributions of source code must retain the above copyright
18 notice, this list of conditions and the following disclaimer.
19 2. Redistributions in binary form must reproduce the above copyright
20 notice, this list of conditions and the following disclaimer in the
21 documentation and/or other materials provided with the distribution.
22 3. Neither the name of the copyright holders nor the
23 names of its contributors may be used to endorse or promote products
24 derived from this software without specific prior written permission.
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
27 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
30 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
33 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 /**************************************************************************/
45 #include "core/cpu/cpu.h"
46 #include "core/pmu/pmu.h"
47 #include "core/adc/adc.h"
49 #ifdef CFG_PRINTF_UART
50 #include "core/uart/uart.h"
54 #include "core/cmd/cmd.h"
58 #include "drivers/chibi/chb.h"
62 #include "core/usbhid-rom/usbhid.h"
66 volatile unsigned int lastTick
;
67 #include "core/usbcdc/usb.h"
68 #include "core/usbcdc/usbcore.h"
69 #include "core/usbcdc/usbhw.h"
70 #include "core/usbcdc/cdcuser.h"
71 #include "core/usbcdc/cdc_buf.h"
75 #include "drivers/lcd/bitmap/st7565/st7565.h"
76 #include "drivers/lcd/smallfonts.h"
80 #include "drivers/lcd/bitmap/ssd1306/ssd1306.h"
81 #include "drivers/lcd/smallfonts.h"
85 #include "drivers/lcd/tft/lcd.h"
86 #include "drivers/lcd/tft/touchscreen.h"
87 #include "drivers/lcd/tft/drawing.h"
91 #include "drivers/eeprom/mcp24aa/mcp24aa.h"
92 #include "drivers/eeprom/eeprom.h"
96 #include "core/pwm/pwm.h"
100 #include "core/ssp/ssp.h"
101 #include "drivers/fatfs/diskio.h"
102 #include "drivers/fatfs/ff.h"
111 /**************************************************************************/
113 Configures the core system clock and sets up any mandatory
114 peripherals like the systick timer, UART for printf, etc.
116 This function should set the HW to the default state you wish to be
117 in coming out of reset/startup, such as disabling or enabling LEDs,
118 setting specific pin states, etc.
120 /**************************************************************************/
123 cpuInit(); // Configure the CPU
124 systickInit(CFG_SYSTICK_DELAY_IN_MS
); // Start systick timer
125 gpioInit(); // Enable GPIO
126 pmuInit(); // Configure power management
127 adcInit(); // Config adc pins to save power
129 // Set LED pin as output and turn LED off
130 gpioSetDir(CFG_LED_PORT
, CFG_LED_PIN
, 1);
131 gpioSetValue(CFG_LED_PORT
, CFG_LED_PIN
, CFG_LED_OFF
);
138 // Initialise UART with the default baud rate
139 #ifdef CFG_PRINTF_UART
140 uint32_t uart
= eepromReadU32(CFG_EEPROM_UART_SPEED
);
141 if ((uart
== 0xFFFFFFFF) || (uart
> 115200))
143 uartInit(CFG_UART_BAUDRATE
); // Use default baud rate
147 uartInit(uart
); // Use baud rate from EEPROM
151 // Initialise PWM (requires 16-bit Timer 1 and P1.9)
156 // Initialise USB HID
161 // Initialise USB CDC
163 lastTick
= systickGetTicks(); // Used to control output/printf timing
164 CDC_Init(); // Initialise VCOM
165 USB_Init(); // USB Initialization
166 USB_Connect(TRUE
); // USB Connect
167 // Wait until USB is configured or timeout occurs
168 uint32_t usbTimeout
= 0;
169 while ( usbTimeout
< CFG_USBCDC_INITTIMEOUT
/ 10 )
171 if (USB_Configuration
) break;
172 systickDelay(10); // Wait 10ms
177 // Printf can now be used with UART or USBCDC
179 // Initialise the ST7565 128x64 pixel display
182 st7565ClearScreen(); // Clear the screen
183 st7565Backlight(1); // Enable the backlight
186 // Initialise the SSD1306 OLED display
188 ssd1306Init(SSD1306_SWITCHCAPVCC
);
189 ssd1306ClearScreen(); // Clear the screen
192 // Initialise TFT LCD Display
198 // Warning: CFG_CHIBI must be disabled if no antenna is connected,
199 // otherwise the SW will halt during initialisation
201 // Write addresses to EEPROM for the first time if necessary
202 // uint16_t addr_short = 0x0025;
203 // uint64_t addr_ieee = 0x0000000000000025;
204 // mcp24aaWriteBuffer(CFG_EEPROM_CHIBI_SHORTADDR, (uint8_t *)&addr_short, 2);
205 // mcp24aaWriteBuffer(CFG_EEPROM_CHIBI_IEEEADDR, (uint8_t *)&addr_ieee, 8);
207 // chb_pcb_t *pcb = chb_get_pcb();
208 // printf("%-40s : 0x%04X%s", "Chibi Initialised", pcb->src_addr, CFG_PRINTF_NEWLINE);
211 // Start the command line interface
217 /**************************************************************************/
219 @brief Sends a single byte to a pre-determined peripheral (UART, etc.).
224 /**************************************************************************/
225 void __putchar(const char c
)
227 #ifdef CFG_PRINTF_UART
228 // Send output to UART
233 /**************************************************************************/
235 @brief Sends a string to a pre-determined end point (UART, etc.).
240 @note This function is only called when using the GCC-compiler
241 in Codelite or running the Makefile manually. This function
242 will not be called when using the C library in Crossworks for
245 /**************************************************************************/
246 int puts(const char * str
)
248 // There must be at least 1ms between USB frames (of up to 64 bytes)
249 // This buffers all data and writes it out from the buffer one frame
250 // and one millisecond at a time
251 #ifdef CFG_PRINTF_USBCDC
252 if (USB_Configuration
)
255 cdcBufferWrite(*str
++);
256 // Check if we can flush the buffer now or if we need to wait
257 unsigned int currentTick
= systickGetTicks();
258 if (currentTick
!= lastTick
)
261 uint32_t bytesRead
= 0;
262 while (cdcBufferDataPending())
264 // Read up to 64 bytes as long as possible
265 bytesRead
= cdcBufferReadLen(frame
, 64);
266 USB_WriteEP (CDC_DEP_IN
, frame
, bytesRead
);
269 lastTick
= currentTick
;
273 // Handle output character by character in __putchar
274 while(*str
) __putchar(*str
++);
This page took 0.055318 seconds and 3 git commands to generate.