irom uint8_t u8g_com_esp8266_ssd_i2c_fn(u8g_t * u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { switch (msg) { case U8G_COM_MSG_INIT: // we assume that the i2c bus was already initialized //u8g_i2c_init(u8g->pin_list[U8G_PI_I2C_OPTION]); platform_i2c_setup(4, 5); break; case U8G_COM_MSG_STOP: break; case U8G_COM_MSG_RESET: /* Currently disabled, but it could be enable. Previous restrictions have been removed */ digitalWrite(D4, arg_val); break; case U8G_COM_MSG_CHIP_SELECT: u8g->pin_list[U8G_PI_A0_STATE] = 0; u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again, also forces start condition */ if (arg_val == 0) { /* disable chip, send stop condition */ platform_i2c_send_stop(); } else { /* enable, do nothing: any byte writing will trigger the i2c start */ } break; case U8G_COM_MSG_WRITE_BYTE: //u8g->pin_list[U8G_PI_SET_A0] = 1; if (u8g_com_esp8266_ssd_start_sequence(u8g) == 0) return platform_i2c_send_stop(), 0; // ignore return value -> tolerate missing ACK if (platform_i2c_send_byte(arg_val) == 0) ; break; case U8G_COM_MSG_WRITE_SEQ: case U8G_COM_MSG_WRITE_SEQ_P: //u8g->pin_list[U8G_PI_SET_A0] = 1; if (u8g_com_esp8266_ssd_start_sequence(u8g) == 0) return platform_i2c_send_stop(), 0; { register uint8_t *ptr = arg_ptr; while (arg_val > 0) { // ignore return value -> tolerate missing ACK if (platform_i2c_send_byte(*ptr++) == 0) ; arg_val--; } } break; case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ u8g->pin_list[U8G_PI_A0_STATE] = arg_val; u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again */ break; } return 1; }
// Lua: speed = i2c.setup( id, speed ) static int i2c_setup( lua_State *L ) { unsigned id = luaL_checkinteger( L, 1 ); u32 speed = ( u32 )luaL_checkinteger( L, 2 ); MOD_CHECK_ID( i2c, id ); lua_pushinteger( L, platform_i2c_setup( id, speed ) ); return 1; }
// Lua: speed = i2c.setup( id, speed ) static int i2c_setup( lua_State *L ) { unsigned id = luaL_checkinteger( L, 1 ); s32 speed = ( s32 )luaL_checkinteger( L, 2 ); MOD_CHECK_ID( i2c, id ); if (speed <= 0) return luaL_error( L, "frequency must be > 0" ); lua_pushinteger( L, platform_i2c_setup( id, (u32)speed ) ); return 1; }
/****************************************************************************** * FunctionName : user_init * Description : entry of user application, init user function here * Parameters : none * Returns : none *******************************************************************************/ void user_init(void) { os_delay_us(1000*1000); uart_init (BIT_RATE_115200, BIT_RATE_115200, USER_TASK_PRIO_0, 0); os_delay_us(100*1000); os_printf("Interactive Cube starting..\n"); config_init(); platform_i2c_setup(i2c_endpoint_id, 1, 2, PLATFORM_I2C_SPEED_SLOW); display_init(); NODE_DBG("SDK version: %s\n", system_get_sdk_version()); system_print_meminfo(); os_printf("Heap size: %d.\n", system_get_free_heap_size()); #ifndef NODE_DEBUG system_set_os_print(1); #endif int b; for(b=0; b<4; b++) { display_set_pixel(0, 1); display_update_inner(); os_delay_us(500*1000); display_update_inner(); display_set_pixel(0, 0); display_update_inner(); os_delay_us(500*1000); display_update_inner(); } if (display_is_key_down(0)) { // enter setup mode, show as blinking...! configui_init(); return; } display_set_pixel(0, 1); display_set_pixel(1, 1); display_set_pixel(2, 1); display_update_inner(); // uart_init(BIT_RATE_9600,0); os_delay_us(100*1000); os_delay_us(1000*1000); display_anim(); // os_delay_us(500*1000); NODE_DBG("Hello Wurst.\n"); // os_delay_us(500*1000); // Set up I2C // Wire.begin(D1, D2); // sda, scl display_set_pixel(0, 0); display_set_pixel(1, 0); display_set_pixel(2, 0); display_set_pixel(3, 0); display_update(); comm_init(); orient_init(); // system_init_done_cb(nodemcu_init); system_os_task(loop, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen); system_os_post(user_procTaskPrio, 0, 0); NODE_DBG("End of user_init.\n"); }