/* simple contents generator */ static char doGet(struct args_t *args) { rflpc_gpio_set_pin_mode_output(MBED_DIP23, 1); rflpc_gpio_set_pin_mode_output(MBED_DIP24, 1); rflpc_gpio_set_pin_mode_output(MBED_DIP25, 1); switch(args->color){ case 0: rflpc_gpio_set_pin(MBED_DIP23); rflpc_gpio_set_pin(MBED_DIP24); rflpc_gpio_set_pin(MBED_DIP25); rflpc_led_set(RFLPC_LED_1); break; case 1: rflpc_gpio_clr_pin(MBED_DIP23); break; case 2: rflpc_gpio_clr_pin(MBED_DIP24);; break; case 3: rflpc_gpio_clr_pin(MBED_DIP25); rflpc_led_set(RFLPC_LED_4); break; } return 1; }
static void _lcd_cmd(uint8_t cmd) { rflpc_gpio_clr_pin(_a0_pin); rflpc_gpio_clr_pin(_cs_pin); rflpc_spi_write(_spi_port, cmd); /* Wait for command to be send */ while (! rflpc_spi_idle(_spi_port)); rflpc_gpio_set_pin(_cs_pin); }
static void _lcd_single_data(uint8_t data) { rflpc_gpio_set_pin(_a0_pin); rflpc_gpio_clr_pin(_cs_pin); rflpc_spi_write(_spi_port, data); while (!rflpc_spi_idle(_spi_port)); rflpc_gpio_set_pin(_cs_pin); }
static void _lcd_multiple_data(uint8_t *data, uint16_t size) { rflpc_gpio_set_pin(_a0_pin); rflpc_gpio_clr_pin(_cs_pin); while (size--) rflpc_spi_write(_spi_port, *data++); while (!rflpc_spi_idle(_spi_port)); rflpc_gpio_set_pin(_cs_pin); }
/*fonction executee a chaque top d'horloge'*/ static void handler(){ /*on change l'etat de cpt qui correspond a si on allume ou si l'on eteint la led*/ cpt = !cpt; /*Si le compteur est a vrai, on allume la LED*/ if (cpt) rflpc_gpio_set_pin(RFLPC_PIN_P0_10); /*Si le compteur est a faux, on eteint la LED*/ else rflpc_gpio_clr_pin(RFLPC_PIN_P0_10); }
void nhd_spi_lcd_init(nhd_display_size_t display_size, rflpc_pin_t reset_pin, rflpc_pin_t a0, rflpc_pin_t cs, rflpc_spi_t port) { _reset_pin = reset_pin; _a0_pin = a0; _spi_port = port; _cs_pin = cs; _display_size = display_size; /* Inits SPI port */ /* The LCD needs a falling edge first clock and expect transmission to start at the edge, not prior */ rflpc_spi_init(_spi_port, RFLPC_SPI_MASTER, RFLPC_CCLK, 8, _get_pre_scale_value(), 2, RFLPC_SPI_CPOL_FALLING_EDGE | RFLPC_SPI_CPHA_PHASE_FIRST_EDGE); /* The application board is a complete mess regarding the pin connections... They use SPI port 1 for clock and MOSI (fine) but... They use - p6 for reset which is... MISO of SPI1 (not that bad, but strange anyway) - p11 for SPI CS which is the hardware controled CS of SPI port... 0 ! bingo (grrrrrr). This will force us to manage CS by hand... pffff */ /* Inits GPIO pins */ rflpc_gpio_set_pin_mode_output(_reset_pin, 1); rflpc_gpio_set_pin_mode_output(_a0_pin, 0); rflpc_gpio_set_pin_mode_output(_cs_pin, 1); /* Perform a reset, reset is active on low */ rflpc_gpio_clr_pin(_reset_pin); RFLPC_DELAY_MICROSECS(100); /* trigger reset, must be low for at least 1 µs, use 10 µs to be sure (ST7565R datasheet, p65) */ rflpc_gpio_set_pin(_reset_pin); RFLPC_DELAY_MICROSECS(100); /* Reset time is 1 µs max. Wait for 10 to be sure */ /* After hard reset (i.e. with the reset pin, what we just did), the controler is in the following state: 1. Display OFF 2. Normal display 3. ADC select: Normal (ADC command D0 = “L”) 4. Power control register: (D2, D1, D0) = (0, 0, 0) 5. 4-line SPI interface internal register data clear 6. LCD power supply bias rate: 1/65 DUTY = 1/9 bias 1/49,1/55,1/53 DUTY = 1/8 bias 1/33 DUTY = 1/6 bias 7. Power saving clear 8. V0 voltage regulator internal resistors Ra and Rb separation 9. Output conditions of SEG and COM terminals SEG=VSS, COM=VSS 10. Read modify write OFF 11. Display start line set to first line 12. Column address set to Address 0 13. Page address set to Page 0 14. Common output status normal 15. V0 voltage regulator internal resistor ratio set mode clear 16. Electronic volume register set mode clear Electronic volume register : (D5, D4, D3, D2, D1, D0) = (1, 0. 0, 0, 0,0) 17. Test mode clear */ LCD_TURN_OFF(); _lcd_cmd(0x22); /* Internal voltage regulator resistance ratio set to have 4V V0 */ _lcd_cmd(0xc8); /* reverse column fill direction. With this setting, fill is from left to right */ LCD_POWER_MODE(1,1,1); /* booster on, regulator on, follower on */ LCD_TURN_ON(); LCD_ALL_PIXELS_OFF(); LCD_START_PAGE(0); }