uint8_t u8g_com_esp8266_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { switch(msg) { case U8G_COM_MSG_STOP: break; case U8G_COM_MSG_INIT: // we assume that the SPI interface was already initialized // just care for the /CS and D/C pins lu8g_digital_write( u8g, U8G_PI_CS, PLATFORM_GPIO_HIGH ); platform_gpio_mode( u8g->pin_list[U8G_PI_CS], PLATFORM_GPIO_OUTPUT, PLATFORM_GPIO_FLOAT ); platform_gpio_mode( u8g->pin_list[U8G_PI_A0], PLATFORM_GPIO_OUTPUT, PLATFORM_GPIO_FLOAT ); break; case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ lu8g_digital_write( u8g, U8G_PI_A0, arg_val == 0 ? PLATFORM_GPIO_LOW : PLATFORM_GPIO_HIGH ); break; case U8G_COM_MSG_CHIP_SELECT: if (arg_val == 0) { /* disable */ lu8g_digital_write( u8g, U8G_PI_CS, PLATFORM_GPIO_HIGH ); } else { /* enable */ //u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, LOW); lu8g_digital_write( u8g, U8G_PI_CS, PLATFORM_GPIO_LOW ); } break; case U8G_COM_MSG_RESET: if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE ) lu8g_digital_write( u8g, U8G_PI_RESET, arg_val == 0 ? PLATFORM_GPIO_LOW : PLATFORM_GPIO_HIGH ); break; case U8G_COM_MSG_WRITE_BYTE: platform_spi_send( 1, 8, arg_val ); break; case U8G_COM_MSG_WRITE_SEQ: case U8G_COM_MSG_WRITE_SEQ_P: { register uint8_t *ptr = arg_ptr; while( arg_val > 0 ) { platform_spi_send( 1, 8, *ptr++ ); arg_val--; } } break; } return 1; }
static int16_t ucg_com_esp8266_hw_spi(ucg_t *ucg, int16_t msg, uint16_t arg, uint8_t *data) { switch(msg) { case UCG_COM_MSG_POWER_UP: /* "data" is a pointer to ucg_com_info_t structure with the following information: */ /* ((ucg_com_info_t *)data)->serial_clk_speed value in nanoseconds */ /* ((ucg_com_info_t *)data)->parallel_clk_speed value in nanoseconds */ /* setup pins */ // we assume that the SPI interface was already initialized // just care for the /CS and D/C pins //platform_gpio_write( ucg->pin_list[0], value ); if ( ucg->pin_list[UCG_PIN_RST] != UCG_PIN_VAL_NONE ) platform_gpio_mode( ucg->pin_list[UCG_PIN_RST], PLATFORM_GPIO_OUTPUT, PLATFORM_GPIO_FLOAT ); platform_gpio_mode( ucg->pin_list[UCG_PIN_CD], PLATFORM_GPIO_OUTPUT, PLATFORM_GPIO_FLOAT ); if ( ucg->pin_list[UCG_PIN_CS] != UCG_PIN_VAL_NONE ) platform_gpio_mode( ucg->pin_list[UCG_PIN_CS], PLATFORM_GPIO_OUTPUT, PLATFORM_GPIO_FLOAT ); break; case UCG_COM_MSG_POWER_DOWN: break; case UCG_COM_MSG_DELAY: delayMicroseconds(arg); break; case UCG_COM_MSG_CHANGE_RESET_LINE: if ( ucg->pin_list[UCG_PIN_RST] != UCG_PIN_VAL_NONE ) platform_gpio_write( ucg->pin_list[UCG_PIN_RST], arg ); break; case UCG_COM_MSG_CHANGE_CS_LINE: if ( ucg->pin_list[UCG_PIN_CS] != UCG_PIN_VAL_NONE ) platform_gpio_write( ucg->pin_list[UCG_PIN_CS], arg ); break; case UCG_COM_MSG_CHANGE_CD_LINE: platform_gpio_write( ucg->pin_list[UCG_PIN_CD], arg ); break; case UCG_COM_MSG_SEND_BYTE: platform_spi_send( 1, 8, arg ); break; case UCG_COM_MSG_REPEAT_1_BYTE: CACHED_TRANSFER(data[0], 1); break; case UCG_COM_MSG_REPEAT_2_BYTES: CACHED_TRANSFER((data[0] << 8) | data[1], 2); break; case UCG_COM_MSG_REPEAT_3_BYTES: while( arg > 0 ) { platform_spi_transaction( 1, 0, 0, 24, (data[0] << 16) | (data[1] << 8) | data[2], 0, 0, 0 ); arg--; } break; case UCG_COM_MSG_SEND_STR: CACHED_TRANSFER(*data++, 1); break; case UCG_COM_MSG_SEND_CD_DATA_SEQUENCE: while(arg > 0) { if ( *data != 0 ) { /* set the data line directly, ignore the setting from UCG_CFG_CD */ if ( *data == 1 ) { platform_gpio_write( ucg->pin_list[UCG_PIN_CD], 0 ); } else { platform_gpio_write( ucg->pin_list[UCG_PIN_CD], 1 ); } } data++; platform_spi_send( 1, 8, *data ); data++; arg--; } break; } return 1; }