Sonochan II 0.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
LCD_5110_HAL_AVR32_UC3A3_HW_interface.h
Go to the documentation of this file.
1
19 #ifndef _LCD_5110_HAL_AVR32_UC3A3_HW_INTERFACE_H_
20 #define _LCD_5110_HAL_AVR32_UC3A3_HW_INTERFACE_H_
21
22 //===========================| Included libraries |============================
23 // Basic library (I/O)
24 #include <avr32/io.h>
25
26 // Data types
27 #include <inttypes.h>
28
29 // Some basic operations with I/O
31 #include "gpio.h"
32
33 //==============================| User settings |==============================
49 #define LCD_5110_CS_support 1
50
69 #define LCD_5110_RESET_support 1
70
81 #define LCD_5110_LIGHT_support 1
82
89 #define LCD_5110_SPI_DEVICE (&AVR32_SPI0)
90
102 #define LCD_5110_SPI_CHIP_SELECT 0
103
119 #define LCD_5110_SPI_CLK_SOURCE 66000000UL
120
122
123
138 #define LCD_5110_SPI_SCK_PIN AVR32_SPI0_SCK_0_0_PIN
139
149 #define LCD_5110_SPI_SCK_FUNCTION AVR32_SPI0_SCK_0_0_FUNCTION
150
159 #define LCD_5110_SPI_MOSI_PIN AVR32_SPI0_MOSI_0_0_PIN
160
169 #define LCD_5110_SPI_MOSI_FUNCTION AVR32_SPI0_MOSI_0_0_FUNCTION
170
183 #define LCD_5110_SPI_CS_PIN AVR32_SPI0_NPCS_0_0_PIN
184
196 #define LCD_5110_SPI_CS_FUNCTION AVR32_SPI0_NPCS_0_0_FUNCTION
197
199
200
201
214 #define LCD_5110_SPI_DC_PIN AVR32_PIN_PA00
215
225 #define LCD_5110_RST_PIN AVR32_PIN_PA05
226
236 #define LCD_5110_LIGHT_PIN AVR32_PIN_PX14
237
239
240
241
242
243
244
245
246
263 #define LCD_5110_SPI_BAUDRATE 0UL
264
278 #define LCD_5110_SPI_TIMEOUT 0UL
279
293 #define LCD_5110_SPI_DELAY_BETWEEN_CS 0
294
306 #define LCD_5110_SPI_DELAY_SCK_START 0
307
319 #define LCD_5110_SPI_DELAY_CS_STOP 0
320
322
323
338 #define LCD_5110_RESET_NUM_OF_CYCLES 0
339
340
342
343
344 //============================| Structures, enums |============================
345
352 typedef enum{
353 LCD_5110_ERROR = -1,
354 LCD_5110_OK = 0,
355 LCD_5110_ERROR_TIMEOUT = 1,
356 LCD_5110_ERROR_SPI_INVALID_PARAMETER = 2
359 } e_lcd_5110_status;
360
361
362
363 //=================================| Macros |==================================
364 #define LCD_5110_IO_LOW_simple(PIN) \
365 gpio_port = \
366 &AVR32_GPIO.port[PIN >> 5]; \
367 gpio_port->ovrc = 1 << (PIN & 0x1F); \
368 gpio_port->oders = 1 << (PIN & 0x1F); \
369 gpio_port->gpers = 1 << (PIN & 0x1F)
370
371
372 #define LCD_5110_IO_LOW(PIN) LCD_5110_IO_LOW_simple(PIN)
373
374
375 #define LCD_5110_IO_HIGH_simple(PIN) \
376 gpio_port = \
377 &AVR32_GPIO.port[PIN >> 5]; \
378 gpio_port->ovrs = 1 << (PIN & 0x1F); \
379 gpio_port->oders = 1 << (PIN & 0x1F); \
380 gpio_port->gpers = 1 << (PIN & 0x1F)
381
382 #define LCD_5110_IO_HIGH(PIN) LCD_5110_IO_HIGH_simple(PIN)
383
384 //================| Some checks and preprocessor calculations |================
385
386
387 #if (LCD_5110_CS_support != 0) && (LCD_5110_CS_support != 1)
388 #error "Please enable (set 1) or disable (set 0) LCD_5110_CS_support"
389 #endif
390
391 #if (LCD_5110_RESET_support != 0) && (LCD_5110_RESET_support != 1)
392 #error "Please enable (set 1) or disable (set 0) LCD_5110_RESET_support"
393 #endif
394
395 #if (LCD_5110_LIGHT_support != 0) && (LCD_5110_LIGHT_support != 1)
396 #error "Please enable (set 1) or disable (set 0) LCD_5110_LIGHT_support"
397 #endif
398
399 // If user let preprocessor define number of cycles
400 #if LCD_5110_RESET_NUM_OF_CYCLES == 0
401 #undef LCD_5110_RESET_NUM_OF_CYCLES
402 #define LCD_5110_RESET_NUM_OF_CYCLES (LCD_5110_SPI_CLK_SOURCE/100)
403 #endif
404
405 #if LCD_5110_SPI_TIMEOUT == 0
406 #undef LCD_5110_SPI_TIMEOUT
407 #define LCD_5110_SPI_TIMEOUT 10000
408 #endif
409
410 // Try to set maximum baudrate if it is wish of user
411 #if LCD_5110_SPI_BAUDRATE == 0
412 #undef LCD_5110_SPI_BAUDRATE
413 // Test if actual clock is lower than 4 MHz
414 #if LCD_5110_SPI_CLK_SOURCE < 4000000
415 #define LCD_5110_SPI_BAUDRATE LCD_5110_SPI_CLK_SOURCE
416 #else
417 // If actual clock is higher than 4 MHz -> try to set maximum baudrate
418 #define LCD_5110_SPI_BAUDRATE 4000000UL
419 #endif
420 #endif
421
422
423 #if LCD_5110_SPI_BAUDRATE > LCD_5110_SPI_CLK_SOURCE
424 #error "SPI baudrate can not be higher than input clock for SPI module. Please\
425 set LCD_5110_SPI_BAUDRATE to lower value, or set it to 0 and preprocessor\
426 try set maximum possible speed."
427 #endif
428
429 #if (LCD_5110_SPI_CLK_SOURCE / LCD_5110_SPI_BAUDRATE) > 255
430 // If calculated SCBR > 255 - can not set this low
431 #error "SPI baudrate can not be set this low! Please set higher baudrate or\
432 lower CLK source for SPI module."
433 #else
434 // Baudrate can be set
435 #define LCD_5110_SPI_SCBR ((LCD_5110_SPI_CLK_SOURCE / LCD_5110_SPI_BAUDRATE))
436 #endif
437
438 // Anyway, check LCD_5110_SPI_SCBR if is 0 -> change to 1
439 #if LCD_5110_SPI_SCBR == 0
440 #undef LCD_5110_SPI_SCBR
441 #define LCD_5110_SPI_SCBR = 1
442 #warning "Value for SCBR was calculated as 0, but this is invalid value. So\
443 SCBR was set to 1. Means that baudrate will be lower then defined by user."
444 #endif
445
446 // test LCD_5110_SPI_DELAY_BETWEEN_CS
447 #if LCD_5110_SPI_DELAY_BETWEEN_CS > 255
448 #error "Sorry, but LCD_5110_SPI_DELAY_BETWEEN_CS can not be higher than 255.\
449 Please set this constant lower. If You need higher delay please consider\
450 lower SPI clock source."
451 #endif
452
453 //================================| Functions |================================
462 e_lcd_5110_status LCD_5110_HAL_init(void);
463
471 e_lcd_5110_status LCD_5110_HAL_send_data_byte(uint8_t i_data);
472
479 e_lcd_5110_status LCD_5110_HAL_send_command_byte(uint8_t i_cmd);
480
489 e_lcd_5110_status LCD_5110_HAL_backlight_on(void);
490
499 e_lcd_5110_status LCD_5110_HAL_backlight_off(void);
500
501
502 #endif