3 #include <core/ssp/ssp.h>
4 #include <core/gpio/gpio.h>
5 #include <core/systick/systick.h>
11 #include <r0ketports.h>
13 #define CS_LOW() gpioSetValue(RB_LCD_CS , 0)
14 #define CS_HIGH() gpioSetValue(RB_LCD_CS , 1)
15 #define RST_LOW() gpioSetValue(RB_LCD_RST, 0)
16 #define RST_HIGH() gpioSetValue(RB_LCD_RST, 1)
20 #include <badge/pinconfig.h>
22 #define CS_LOW() gpioSetValue(HOB_PORT(HOB_LCD_CS ), HOB_PIN(HOB_LCD_CS ), 0)
23 #define CS_HIGH() gpioSetValue(HOB_PORT(HOB_LCD_CS ), HOB_PIN(HOB_LCD_CS ), 1)
24 #define RST_LOW() gpioSetValue(HOB_PORT(HOB_LCD_RST), HOB_PIN(HOB_LCD_RST), 0)
25 #define RST_HIGH() gpioSetValue(HOB_PORT(HOB_LCD_RST), HOB_PIN(HOB_LCD_RST), 1)
30 #include <core/usbhid-rom/usbmsc.h>
32 static uint32_t usbintstatus
;
35 static void lcd_select() {
38 usbintstatus
= USB_DEVINTEN
;
43 /* the LCD requires 9-Bit frames */
44 uint32_t configReg
= ( SSP_SSP0CR0_DSS_9BIT
// Data size = 9-bit
45 | SSP_SSP0CR0_FRF_SPI
// Frame format = SPI
46 | SSP_SSP0CR0_SCR_8
); // Serial clock rate = 8
47 SSP_SSP0CR0
= configReg
;
52 static void lcd_deselect() {
54 /* reset the bus to 8-Bit frames that everyone else uses */
55 uint32_t configReg
= ( SSP_SSP0CR0_DSS_8BIT
// Data size = 8-bit
56 | SSP_SSP0CR0_FRF_SPI
// Frame format = SPI
57 | SSP_SSP0CR0_SCR_8
); // Serial clock rate = 8
58 SSP_SSP0CR0
= configReg
;
62 USB_DEVINTEN
= usbintstatus
;
67 static inline void lcd_write(uint16_t frame
) {
68 while ((SSP_SSP0SR
& (SSP_SSP0SR_TNF_NOTFULL
| SSP_SSP0SR_BSY_BUSY
)) != SSP_SSP0SR_TNF_NOTFULL
);
70 while ((SSP_SSP0SR
& (SSP_SSP0SR_BSY_BUSY
|SSP_SSP0SR_RNE_NOTEMPTY
)) != SSP_SSP0SR_RNE_NOTEMPTY
);
75 static void lcd_write_command(uint8_t data
) { lcd_write( data
); }
76 static void lcd_write_data (uint8_t data
) { lcd_write(0x0100 | data
); }
78 void badge_display_init(void) {
79 sspInit(0, sspClockPolarity_Low
, sspClockPhase_RisingEdge
);
90 int id = lcdRead(220);
93 gpioSetDir(1, 7, gpioDirection_Output);
94 gpioSetValue(1, 7, 1);
98 /* Small Nokia 1200 LCD docs:
102 * mirror-x 0xA0 / 0xA1
103 * mirror-y 0xc7 / 0xc8
105 * 0x20+x contrast (0=black - 0x2e)
106 * 0x40+x offset in rows from top (-0x7f)
107 * 0x80+x contrast? (0=black -0x9f?)
108 * 0xd0+x black lines from top? (-0xdf?)
115 * AF: Display on/off: DON = 1
117 * A4: all on/normal: DAL = 0
118 * 2F: charge pump on/off: PC = 1
119 * B0: set y address: Y[0-3] = 0
120 * 10: set x address (upper bits): X[6-4] = 0
122 static uint8_t const initseq
[]= { 0xE2, 0xAF, // Display ON
125 0xa7, // invert (1 = black)
130 for(uint8_t i
= 0; i
< sizeof(initseq
); ++i
){
131 lcd_write_command(initseq
[i
]);
138 void badge_framebuffer_flush(badge_framebuffer
const *fb
) {
141 lcd_write_command(0xb0);
142 lcd_write_command(0x10);
143 lcd_write_command(0x00);
146 for(int i
= 0; i
< BADGE_DISPLAY_STRIPE_COUNT
* BADGE_DISPLAY_WIDTH
; ++i
) {
147 lcd_write_data(fb
->data
[0][i
]);