2 * This file is subject to the terms of the GFX License. If a copy of
3 * the license was not distributed with this file, you can obtain one at:
5 * http://ugfx.org/license.html
8 #ifndef _GDISP_LLD_BOARD_H
9 #define _GDISP_LLD_BOARD_H
11 #define ST7565_LCD_BIAS ST7565_LCD_BIAS_9 // actually 6
12 #define ST7565_ADC ST7565_ADC_NORMAL
13 #define ST7565_COM_SCAN ST7565_COM_SCAN_DEC
14 #define ST7565_PAGE_ORDER 0,1,2,3
16 * Custom page order for several LCD boards, e.g. HEM12864-99
17 * #define ST7565_PAGE_ORDER 4,5,6,7,0,1,2,3
20 #define ST7565_GPIOPORT GPIOC
21 #define ST7565_PORT PORTC
22 #define ST7565_A0_PIN 7
23 #define ST7565_RST_PIN 8
24 #define ST7565_MOSI_PIN 6
25 #define ST7565_SLCK_PIN 5
26 #define ST7565_SS_PIN 4
28 #define palSetPadModeRaw(portname, bits) \
29 ST7565_PORT->PCR[ST7565_##portname##_PIN] = bits
31 #define palSetPadModeNamed(portname, portmode) \
32 palSetPadMode(ST7565_GPIOPORT, ST7565_##portname##_PIN, portmode)
34 #define ST7565_SPI_MODE PORTx_PCRn_DSE | PORTx_PCRn_MUX(2)
35 // DSPI Clock and Transfer Attributes
39 static const SPIConfig spi1config
= {
40 // Operation complete callback or @p NULL.
42 //The chip select line port - when not using pcs.
43 .ssport
= ST7565_GPIOPORT
,
44 // brief The chip select line pad number - when not using pcs.
46 // SPI initialization data.
48 SPIx_CTARn_FMSZ(7) // Frame size = 8 bytes
49 | SPIx_CTARn_ASC(1) // After SCK Delay Scaler (min 50 ns) = 55.56ns
50 | SPIx_CTARn_DT(0) // Delay After Transfer Scaler (no minimum)= 27.78ns
51 | SPIx_CTARn_CSSCK(0) // PCS to SCK Delay Scaler (min 20 ns) = 27.78ns
52 | SPIx_CTARn_PBR(0) // Baud Rate Prescaler = 2
53 | SPIx_CTARn_BR(0) // Baud rate (min 50ns) = 55.56ns
56 static GFXINLINE
void acquire_bus(GDisplay
*g
) {
58 // Only the LCD is using the SPI bus, so no need to acquire
59 // spiAcquireBus(&SPID1);
63 static GFXINLINE
void release_bus(GDisplay
*g
) {
65 // Only the LCD is using the SPI bus, so no need to release
66 //spiReleaseBus(&SPID1);
70 static GFXINLINE
void init_board(GDisplay
*g
) {
72 palSetPadModeNamed(A0
, PAL_MODE_OUTPUT_PUSHPULL
);
73 palSetPad(ST7565_GPIOPORT
, ST7565_A0_PIN
);
74 palSetPadModeNamed(RST
, PAL_MODE_OUTPUT_PUSHPULL
);
75 palSetPad(ST7565_GPIOPORT
, ST7565_RST_PIN
);
76 palSetPadModeRaw(MOSI
, ST7565_SPI_MODE
);
77 palSetPadModeRaw(SLCK
, ST7565_SPI_MODE
);
78 palSetPadModeNamed(SS
, PAL_MODE_OUTPUT_PUSHPULL
);
81 spiStart(&SPID1
, &spi1config
);
85 static GFXINLINE
void post_init_board(GDisplay
*g
) {
89 static GFXINLINE
void setpin_reset(GDisplay
*g
, bool_t state
) {
92 palClearPad(ST7565_GPIOPORT
, ST7565_RST_PIN
);
95 palSetPad(ST7565_GPIOPORT
, ST7565_RST_PIN
);
99 static GFXINLINE
void enter_data_mode(GDisplay
*g
) {
100 palSetPad(ST7565_GPIOPORT
, ST7565_A0_PIN
);
103 static GFXINLINE
void enter_cmd_mode(GDisplay
*g
) {
104 palClearPad(ST7565_GPIOPORT
, ST7565_A0_PIN
);
108 static GFXINLINE
void write_data(GDisplay
*g
, uint8_t* data
, uint16_t length
) {
110 spiSend(&SPID1
, length
, data
);
113 #endif /* _GDISP_LLD_BOARD_H */