X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=boards%2Fsam3x-ek%2Fhw%2Fhw_hx8347.h;fp=boards%2Fsam3x-ek%2Fhw%2Fhw_hx8347.h;h=541f284926cfed89ff86354cfa48c09eca1626a0;hb=97a3b5115cb89465a7f9bf16cb657aca46ff9841;hp=0000000000000000000000000000000000000000;hpb=b3eb079f0ff76073493cba30f64783f94c044b95;p=bertos.git diff --git a/boards/sam3x-ek/hw/hw_hx8347.h b/boards/sam3x-ek/hw/hw_hx8347.h new file mode 100644 index 00000000..541f2849 --- /dev/null +++ b/boards/sam3x-ek/hw/hw_hx8347.h @@ -0,0 +1,163 @@ +/** + * \file + * + * + * \brief HX8347 low-level hardware macros for Atmel SAM3X-EK board. + * + * The LCD controller is connected to the cpu static memory controller. + * LCD has 16 data lines and usual RS/WR/RD lines. The data lines + * are connected to the SMC data bus (D0-15), while the SCM address bus + * (A1 only) is used to drive the RS pin. WR/RD are connected to SMC's + * NWE and NRD respectively. + * + * \author Stefano Fedrigo + */ + +#ifndef HW_HX8347_H +#define HW_HX8347_H + +#include "cfg/macros.h" +#include + + +/* + * LCD I/O pins/ports and peripherals + */ +#define LCD_DATABUS_PINS (0xFFFF << 2) +#define LCD_DATABUS_PORT PIOC_BASE +#define LCD_DATABUS_PERIPH PIO_PERIPH_A + +#define LCD_NRD_PIN BV(29) +#define LCD_NRD_PORT PIOA_BASE +#define LCD_NRD_PERIPH PIO_PERIPH_B + +#define LCD_NWE_PIN BV(18) +#define LCD_NWE_PORT PIOC_BASE +#define LCD_NWE_PERIPH PIO_PERIPH_A + +#define LCD_NCS2_PIN BV(24) +#define LCD_NCS2_PORT PIOB_BASE +#define LCD_NCS2_PERIPH PIO_PERIPH_B + +#define LCD_RS_PIN BV(22) +#define LCD_RS_PORT PIOC_BASE +#define LCD_RS_PERIPH PIO_PERIPH_A + + +// How many cpu clocks per nanosecond. +#define CLOCKS_PER_NS(ns) ((uint32_t)((ns * (CPU_FREQ/1000000)) / 1000) + 1) + + +// LCD Base Address, chip select 2 +#define LCD_BASE 0x62000000 + +// LCD index register address +#define LCD_IR (*(uint16_t *)(LCD_BASE)) + +// LCD data address (A1 drives RS signal) +#define LCD_D (*(uint16_t *)(LCD_BASE + 2)) + +/** + * Send a command to LCD controller. + */ +INLINE void hx8347_cmd(uint8_t cmd) +{ + LCD_IR = cmd; +} + +/** + * Send data to LCD controller. + */ +INLINE void hx8347_write(uint16_t data) +{ + LCD_D = data; +} + +/** + * Read data from LCD controller. + */ +INLINE uint16_t hx8347_read(void) +{ + return LCD_D; +} + +/** + * Bus initialization: on SAM3X-EK the display is wired + * on the static memory controller, chip select 2. + */ +INLINE void hx8347_busInit(void) +{ + // Configure pins: disable PIO... + HWREG(LCD_DATABUS_PORT + PIO_PDR_OFF) = LCD_DATABUS_PINS; + HWREG(LCD_NRD_PORT + PIO_PDR_OFF) = LCD_NRD_PIN; + HWREG(LCD_NWE_PORT + PIO_PDR_OFF) = LCD_NWE_PIN; + HWREG(LCD_NCS2_PORT + PIO_PDR_OFF) = LCD_NCS2_PIN; + HWREG(LCD_RS_PORT + PIO_PDR_OFF) = LCD_RS_PIN; + + // ... enable pull-up... + HWREG(LCD_DATABUS_PORT + PIO_PUER_OFF) = LCD_DATABUS_PINS; + HWREG(LCD_NRD_PORT + PIO_PUER_OFF) = LCD_NRD_PIN; + HWREG(LCD_NWE_PORT + PIO_PUER_OFF) = LCD_NWE_PIN; + HWREG(LCD_NCS2_PORT + PIO_PUER_OFF) = LCD_NCS2_PIN; + HWREG(LCD_RS_PORT + PIO_PUER_OFF) = LCD_RS_PIN; + + // ... and select appropriate peripheral. + PIO_PERIPH_SEL(LCD_DATABUS_PORT, LCD_DATABUS_PINS, LCD_DATABUS_PERIPH); + PIO_PERIPH_SEL(LCD_NRD_PORT, LCD_NRD_PIN, LCD_NRD_PERIPH); + PIO_PERIPH_SEL(LCD_NWE_PORT, LCD_NWE_PIN, LCD_NWE_PERIPH); + PIO_PERIPH_SEL(LCD_NCS2_PORT, LCD_NCS2_PIN, LCD_NCS2_PERIPH); + PIO_PERIPH_SEL(LCD_RS_PORT, LCD_RS_PIN, LCD_RS_PERIPH); + + // Enable peripheral clock + PMC_PCER = SMC_SDRAMC_ID; + + // Static memory controller configuration + SMC_SETUP2 = + SMC_SETUP_NWE_SETUP(CLOCKS_PER_NS(10)) | + SMC_SETUP_NCS_WR_SETUP(CLOCKS_PER_NS(10)) | + SMC_SETUP_NRD_SETUP(CLOCKS_PER_NS(90)) | + SMC_SETUP_NCS_RD_SETUP(CLOCKS_PER_NS(90)); + + SMC_PULSE2 = + SMC_PULSE_NWE_PULSE(CLOCKS_PER_NS(35)) | + SMC_PULSE_NCS_WR_PULSE(CLOCKS_PER_NS(35)) | + SMC_PULSE_NRD_PULSE(CLOCKS_PER_NS(355)) | + SMC_PULSE_NCS_RD_PULSE(CLOCKS_PER_NS(355)); + + SMC_CYCLE2 = + SMC_CYCLE_NWE_CYCLE(CLOCKS_PER_NS(100)) | + SMC_CYCLE_NRD_CYCLE(CLOCKS_PER_NS(460)); + + SMC_MODE2 = + SMC_MODE_WRITE_MODE | SMC_MODE_READ_MODE | SMC_MODE_DBW; +} + +#endif /* HW_HX8347_H */