rt_err_t wm_spi_bus_attach_device(const char *bus_name, const char *device_name, rt_uint32_t pin) { rt_err_t ret; rt_int16_t gpio_pin; struct rt_spi_device *spi_device; struct wm_sw_spi_cs *cs_pin; gpio_pin = wm_get_pin(pin); if (gpio_pin == WM_PIN_DEFAULT) { return -RT_ERROR; } spi_device = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device)); RT_ASSERT(spi_device != RT_NULL); cs_pin = (struct wm_sw_spi_cs *)rt_malloc(sizeof(struct wm_sw_spi_cs)); RT_ASSERT(cs_pin != RT_NULL); cs_pin->pin = gpio_pin; tls_gpio_cfg((enum tls_io_name)gpio_pin, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLHIGH); tls_gpio_write((enum tls_io_name)gpio_pin, 1); ret = rt_spi_bus_attach_device(spi_device, device_name, bus_name, (void *)cs_pin); return ret; }
static void codec_isr_init(void) { u16 gpio_pin; gpio_pin = DAT_REQ; tls_gpio_cfg(gpio_pin, TLS_GPIO_DIR_INPUT, TLS_GPIO_ATTR_PULLHIGH); tls_gpio_isr_register(codec_isr_callback,NULL); tls_gpio_int_enable(gpio_pin, TLS_GPIO_INT_TRIG_FALLING_EDGE); }
int CreateMediaRender(char * buf) { void *msg; tls_os_status_t status; u8 uuid[17] = {0}; u8 *mac = wpa_supplicant_get_mac(); sprintf((char *)uuid, "%02x%02x%02x%02x%02x%02x-dmr", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); tls_dmr_init((char *)uuid, (char *)uuid); tls_gpio_cfg(SPI_CLK, TLS_GPIO_DIR_OUTPUT, TLS_GPIO_ATTR_FLOATING); tls_gpio_cfg(SPI_DATO, TLS_GPIO_DIR_OUTPUT, TLS_GPIO_ATTR_FLOATING); tls_gpio_cfg(SPI_CCS, TLS_GPIO_DIR_OUTPUT, TLS_GPIO_ATTR_PULLHIGH); tls_gpio_cfg(DAT_REQ, TLS_GPIO_DIR_INPUT, TLS_GPIO_ATTR_FLOATING); tls_gpio_cfg(LED, TLS_GPIO_DIR_OUTPUT, TLS_GPIO_ATTR_PULLHIGH); tls_gpio_cfg(RST, TLS_GPIO_DIR_OUTPUT, TLS_GPIO_ATTR_PULLHIGH); // tls_gpio_cfg(RUN_MODE, TLS_GPIO_DIR_INPUT, TLS_GPIO_ATTR_FLOATING); SPI_CS(1); LED_ON(0); msg = tls_mem_alloc(64 * sizeof(void *)); if (!msg) return -1; status = tls_os_queue_create(&sd_down_mbox, msg, 64, 0); if (status != TLS_OS_SUCCESS) { tls_mem_free(msg); return -1; } tls_os_task_create(NULL, NULL, sd_down_thread, NULL, (void *)sd_down_task_stk, UPNP_SD_STK_SIZE * sizeof(u32), DEMO_DMR_TASK_PRIO,//DEMO_DMR_TASK_PRIO, 0); tls_dmr_set_play_callback(httpdownloadmusic); tls_dmr_set_stop_callback(httpstopdownloadmusic); tls_dmr_set_seek_callback(httpstopdownloadmusic); tls_dmr_set_pause_callback(httpstopdownloadmusic); tls_dmr_set_play_progress_callback(get_grogress); tls_dmr_set_mute_callback(mute_callback); tls_dmr_set_volume_callback(volume_callback); tls_dmr_set_volumedb_callback(volumedb_callback); tls_dmr_set_loudness_callback(loudness_callback); return 0; }
int spi_demo(char *buf) { // int time; tls_spi_slave_sel(SPI_SLAVE_CARD); tls_spi_trans_type(2); tls_spi_setup(TLS_SPI_MODE_0, TLS_SPI_CS_LOW, 100000); #if CS_CTRL_SOFT tls_reg_write32(HR_IOCTL_GP_SPI, 2); //cs 作为gpio18使用 tls_gpio_cfg(18, TLS_GPIO_DIR_OUTPUT, TLS_GPIO_ATTR_PULLLOW); #endif TestSPIReceiveData(); #if 1 // while(1) { TestSPITransferCMD(); TestSPIReceiveData(); OSTimeDly(10); } #endif #if 0 time = OSTimeGet(); printf("\ntime1 = %d\n",time); for(i = 0;i < 1000;i ++) #endif { //TestSPITransferData(); } #if 0 time = OSTimeGet(); printf("\ntime1 = %d\n",time); #endif return WM_SUCCESS; }
static void BlinkTimerProc(void) { // #define HIO_LINK 13 #define HIO_LINK 11 static u32 div_blink = 0; static u32 mode_blink = 0; u32 blink[][2] = { /************************************************ |<--------blink------->| |<--light-->| |-----------| |-----------| | | | | ---| |----------| |--- blink | light *************************************************/ {22, 2}, /* mode = 0 */ {10, 5}, /* mode = 1 */ {2, 1}, /* mode = 2 */ }; u32 mode; mode = net_up_status?1:0; if(tls_fwup_get_status()) { mode = 2; } if (mode != mode_blink) { mode_blink = mode; div_blink = 0; } tls_gpio_cfg(HIO_LINK, TLS_GPIO_DIR_OUTPUT, TLS_GPIO_ATTR_FLOATING); if(blink[mode_blink][0] == 0) { if (blink[mode_blink][1] == 0) { tls_gpio_write(HIO_LINK, 0); } else { tls_gpio_write(HIO_LINK, 1); } } else { ++div_blink; if (div_blink <= blink[mode_blink][1]) { tls_gpio_write(HIO_LINK, 1); } else if (div_blink <= blink[mode_blink][0]) { tls_gpio_write(HIO_LINK, 0); } else { div_blink = 0; } } }