3 #include <core/ssp/ssp.h>
4 #include <core/gpio/gpio.h>
5 #include <core/systick/systick.h>
9 #include <r0ketports.h>
12 #include <core/usbhid-rom/usbmsc.h>
14 static uint32_t usbintstatus
;
17 static void lcd_select() {
20 usbintstatus
= USB_DEVINTEN
;
25 /* the LCD requires 9-Bit frames */
26 uint32_t configReg
= ( SSP_SSP0CR0_DSS_9BIT
// Data size = 9-bit
27 | SSP_SSP0CR0_FRF_SPI
// Frame format = SPI
28 | SSP_SSP0CR0_SCR_8
); // Serial clock rate = 8
29 SSP_SSP0CR0
= configReg
;
30 gpioSetValue(RB_LCD_CS
, 0);
33 static void lcd_deselect() {
34 gpioSetValue(RB_LCD_CS
, 1);
35 /* reset the bus to 8-Bit frames that everyone else uses */
36 uint32_t configReg
= ( SSP_SSP0CR0_DSS_8BIT
// Data size = 8-bit
37 | SSP_SSP0CR0_FRF_SPI
// Frame format = SPI
38 | SSP_SSP0CR0_SCR_8
); // Serial clock rate = 8
39 SSP_SSP0CR0
= configReg
;
43 USB_DEVINTEN
= usbintstatus
;
48 static inline void lcd_write(uint16_t frame
) {
49 while ((SSP_SSP0SR
& (SSP_SSP0SR_TNF_NOTFULL
| SSP_SSP0SR_BSY_BUSY
)) != SSP_SSP0SR_TNF_NOTFULL
);
51 while ((SSP_SSP0SR
& (SSP_SSP0SR_BSY_BUSY
|SSP_SSP0SR_RNE_NOTEMPTY
)) != SSP_SSP0SR_RNE_NOTEMPTY
);
56 static void lcd_write_command(uint8_t data
) { lcd_write( data
); }
57 static void lcd_write_data (uint8_t data
) { lcd_write(0x0100 | data
); }
59 void badge_display_init(void) {
60 sspInit(0, sspClockPolarity_Low
, sspClockPhase_RisingEdge
);
62 gpioSetValue(RB_LCD_CS
, 1);
63 gpioSetValue(RB_LCD_RST
, 1);
65 gpioSetDir (RB_LCD_CS
, gpioDirection_Output
);
66 gpioSetDir (RB_LCD_RST
, gpioDirection_Output
);
69 gpioSetValue(RB_LCD_RST
, 0);
71 gpioSetValue(RB_LCD_RST
, 1);
74 int id = lcdRead(220);
77 gpioSetDir(1, 7, gpioDirection_Output);
78 gpioSetValue(1, 7, 1);
82 /* Small Nokia 1200 LCD docs:
86 * mirror-x 0xA0 / 0xA1
87 * mirror-y 0xc7 / 0xc8
89 * 0x20+x contrast (0=black - 0x2e)
90 * 0x40+x offset in rows from top (-0x7f)
91 * 0x80+x contrast? (0=black -0x9f?)
92 * 0xd0+x black lines from top? (-0xdf?)
99 * AF: Display on/off: DON = 1
101 * A4: all on/normal: DAL = 0
102 * 2F: charge pump on/off: PC = 1
103 * B0: set y address: Y[0-3] = 0
104 * 10: set x address (upper bits): X[6-4] = 0
106 static uint8_t const initseq
[]= { 0xE2, 0xAF, // Display ON
109 0xa7, // invert (1 = black)
114 for(uint8_t i
= 0; i
< sizeof(initseq
); ++i
){
115 lcd_write_command(initseq
[i
]);
122 void badge_framebuffer_flush(badge_framebuffer
const *fb
) {
125 lcd_write_command(0xb0);
126 lcd_write_command(0x10);
127 lcd_write_command(0x00);
130 for(int i
= 0; i
< BADGE_DISPLAY_STRIPE_COUNT
* BADGE_DISPLAY_WIDTH
; ++i
) {
131 lcd_write_data(fb
->data
[0][i
]);