/* * Miscelaneous platform dependent initialisations */ int board_init(void) { /* arch number of PDNB3 */ gd->bd->bi_arch_number = MACH_TYPE_PDNB3; /* adress of boot parameters */ gd->bd->bi_boot_params = 0x00000100; GPIO_OUTPUT_SET(CONFIG_SYS_GPIO_FPGA_RESET); GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_FPGA_RESET); GPIO_OUTPUT_SET(CONFIG_SYS_GPIO_SYS_RUNNING); GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_SYS_RUNNING); /* * Setup GPIO's for FPGA programming */ GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_PRG); GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_CLK); GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_DATA); GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_PRG); GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_CLK); GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_DATA); GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_INIT); GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_DONE); /* * Setup GPIO's for interrupts */ GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_PCI_INTA); GPIO_INT_ACT_LOW_SET(CONFIG_SYS_GPIO_PCI_INTA); GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_PCI_INTB); GPIO_INT_ACT_LOW_SET(CONFIG_SYS_GPIO_PCI_INTB); GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_RESTORE_INT); GPIO_INT_ACT_LOW_SET(CONFIG_SYS_GPIO_RESTORE_INT); GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_RESTART_INT); GPIO_INT_ACT_LOW_SET(CONFIG_SYS_GPIO_RESTART_INT); /* * Setup GPIO's for 33MHz clock output */ *IXP425_GPIO_GPCLKR = 0x01FF0000; GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_CLK_33M); /* * Setup other chip select's */ *IXP425_EXP_CS1 = CONFIG_SYS_EXP_CS1; return 0; }
void gpio_rutine(void){ static int i = 0; if (short_press_flag) { if (i++ == 0) { GPIO_OUTPUT_SET(PWBTN_PIN, 1); } else if (i > PWBTN_SHORT_PRESS_TICKS) { GPIO_OUTPUT_SET(PWBTN_PIN, 0); short_press_flag = 0; i = 0; } } else if (long_press_flag) { if (i++ == 0) { GPIO_OUTPUT_SET(PWBTN_PIN, 1); } else if (i > PWBTN_LONG_PRESS_TICKS) { GPIO_OUTPUT_SET(PWBTN_PIN, 0); long_press_flag = 0; i = 0; } } else if (hardrest_press_flag) { if (i++ == 0) { GPIO_OUTPUT_SET(PWBTN_PIN, 1); } else if (i == PWBTN_LONG_PRESS_TICKS) { GPIO_OUTPUT_SET(PWBTN_PIN, 0); } else if(i == PWBTN_LONG_PRESS_TICKS + PWBTN_HARDRESET_PAUSE_TICKS){ GPIO_OUTPUT_SET(PWBTN_PIN, 1); } else if(i > PWBTN_LONG_PRESS_TICKS + PWBTN_HARDRESET_PAUSE_TICKS + PWBTN_SHORT_PRESS_TICKS){ GPIO_OUTPUT_SET(PWBTN_PIN, 0); hardrest_press_flag = 0; i = 0; } } }
void blink(void) { static bool state = false; // Used to toggle LED state if(state == true) { GPIO_OUTPUT_SET(LED_PIN, 1); // Turn LED on state = false; } else { GPIO_OUTPUT_SET(LED_PIN, 0); // Turn LED off state = true; } }
///////////////////////////////////////////////////////////// // blink() - Changes the state of the LED each time called // ///////////////////////////////////////////////////////////// void blink(void) { static bool flag = false; if (flag) { GPIO_OUTPUT_SET(LED_PIN, 1); flag = false; } else { GPIO_OUTPUT_SET(LED_PIN, 0); flag = true; } }
/** * called first at OS init */ void ICACHE_FLASH_ATTR valveDriverInit() { // configure GPIO outputs PIN_FUNC_SELECT(GENERATOR_GPIO_MUX, GENERATOR_GPIO_FUNC); PIN_FUNC_SELECT(OPEN_VALVE_GPIO_MUX, OPEN_VALVE_GPIO_FUNC); PIN_FUNC_SELECT(CLOSE_VALVE_GPIO_MUX, CLOSE_VALVE_GPIO_FUNC); PIN_FUNC_SELECT(CAPACITOR_GPIO_MUX, CAPACITOR_GPIO_FUNC); // configure passive output state GPIO_OUTPUT_SET(GENERATOR_GPIO, 0); GPIO_DIS_OUTPUT(OPEN_VALVE_GPIO); GPIO_OUTPUT_SET(CLOSE_VALVE_GPIO, 0); GPIO_DIS_OUTPUT(CAPACITOR_GPIO); }
void ICACHE_FLASH_ATTR lpd6803_init() { gpio_init(); //Set GPIO2 to output mode for CLCK PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2); GPIO_OUTPUT_SET(2, 0); //Set GPIO0 to output mode for DATA PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0); GPIO_OUTPUT_SET(0, 0); uint16_t i; for (i = 0; i < numLEDs; i++) { lpd6803_setPixelColor(i, 0, 0, 0); } }
// same as callback function in Arduino void ICACHE_FLASH_ATTR mqttDataCb(uint32_t *args, const char* topic, uint32_t topic_len, const char *data, uint32_t data_len) { char topicBuf[64], dataBuf[64]; MQTT_Client* client = (MQTT_Client*)args; os_memcpy(topicBuf, topic, topic_len); topicBuf[topic_len] = 0; os_memcpy(dataBuf, data, data_len); dataBuf[data_len] = 0; // HERE STARTS THE BASIC LOGIC BY KONSTANTIN // GPIO2 handling here /* if (strcmp(topicBuf,PIN_GPIO2_TOPIC)==0) { if (strcmp(dataBuf,"OFF")==0) { GPIO_OUTPUT_SET(PIN_GPIO2, 0); INFO("GPIO2 set to OFF\r\n"); MQTT_Publish(&mqttClient,PIN_GPIO2_TOPIC_CB,"OFF",3,0,0); currGPIO2State=0; } else if (strcmp(dataBuf,"ON")==0) { GPIO_OUTPUT_SET(PIN_GPIO2, 1); INFO("GPIO2 set to ON\r\n"); MQTT_Publish(&mqttClient,PIN_GPIO2_TOPIC_CB,"ON",2,0,0); currGPIO2State=1; } } /* */ // GPIO4 handling here if (strcmp(topicBuf,PIN_GPIO4_TOPIC)==0) { if (strcmp(dataBuf,"OFF")==0) { GPIO_OUTPUT_SET(PIN_GPIO4, 0); INFO("GPIO4 set to OFF\r\n"); MQTT_Publish(&mqttClient,PIN_GPIO4_TOPIC_CB,"OFF",3,0,0); currGPIO4State=0; } else if (strcmp(dataBuf,"ON")==0) { GPIO_OUTPUT_SET(PIN_GPIO4, 1); INFO("GPIO4 set to ON\r\n"); MQTT_Publish(&mqttClient,PIN_GPIO4_TOPIC_CB,"ON",2,0,0); currGPIO4State=1; } } // HERE ENDS THE BASIC LOGIC BY KONSTANTIN // INFO("GPIO2 State: %d",GPIO_INPUT_GET(PIN_GPIO)); INFO("MQTT topic: %s, data: %s \r\n", topicBuf, dataBuf); // os_free(topicBuf); // os_free(dataBuf); }
static void ICACHE_FLASH_ATTR alarm_timer_cb(void* arg) { if(alarm_counter) { PRINTF("alarm time, state:%u, alarm_counter:%u\n", alarm_state, alarm_counter); GPIO_OUTPUT_SET(ALARM_GPIO_ID, alarm_state); if(alarm_state) { alarm_state = 0; } else { alarm_state = 1; } alarm_counter++; } if(alarm_counter >= COUNTER_TO_CLEAR_ALARM) { PRINTF("alarm time end\n"); alarm_counter = 0; alarm_state = 0; os_timer_disarm(&alarm_timer); } }
/** * Set the value of the corresponding pin. */ void jshPinSetValue(Pin pin, //!< The pin to have its value changed. bool value //!< The new value of the pin. ) { // Debug // os_printf("> ESP8266: jshPinSetValue %d, %d\n", pin, value); GPIO_OUTPUT_SET(pin, value); }
void init_relay() { // make sure GPIOs enabled to GPIO function not alternate function PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2); PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO4_U, FUNC_GPIO4); PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO5_U, FUNC_GPIO5); GPIO_OUTPUT_SET(SDATA, 0); GPIO_OUTPUT_SET(SCLK, 0); GPIO_OUTPUT_SET(SLAT, 0); relay_data = 0; send_relay(); }
/****************************************************************************** * FunctionName : user_esp_platform_check_ip * Description : check whether get ip addr or not * Parameters : none * Returns : none *******************************************************************************/ void ICACHE_FLASH_ATTR user_esp_platform_check_ip(void) { struct ip_info ipconfig; //disarm timer first os_timer_disarm(&test_timer); //get ip info of ESP8266 station wifi_get_ip_info(STATION_IF, &ipconfig); if (wifi_station_get_connect_status() == STATION_GOT_IP && ipconfig.ip.addr != 0) { printf("got ip !!! \r\n"); user_tcpserver_init(SERVER_LOCAL_PORT); GPIO_OUTPUT_SET(LED_GPIO, 1); } else { if ((wifi_station_get_connect_status() == STATION_WRONG_PASSWORD || wifi_station_get_connect_status() == STATION_NO_AP_FOUND || wifi_station_get_connect_status() == STATION_CONNECT_FAIL)) { printf("connect fail !!! \r\n"); } else { //re-arm timer to check ip os_timer_setfn(&test_timer, (os_timer_func_t *)user_esp_platform_check_ip, NULL); os_timer_arm(&test_timer, 100, 0); } } }
int8_t ICACHE_FLASH_ATTR cb_gpio_set_gpio2(uint8_t IsFirstCall, char* OutputData, uint16_t MaxBytes, uint16_t* RetBytes, uint8_t* RetDone){ /* TAG CALLBACK FUNCTION for [[GPIO_SET_GPIO2]] * -------------------------------------------- * ! See whttpd_pp_item_struct structure definition to know what is passed to / what is expected from tag callback function. * ! This function could be called multiple times for one tag, if we signal by RetDone that we didn't end yet (probably because MaxBytes was less that what we needed). */ //allocate memory for OutString (local) char* OutString = malloc(5); //!make sure that all your error code strings will fit if(OutString==NULL){ *RetBytes = 0; *RetDone = 1; return -1; } if(IsFirstCall) cb_gsg2_CopiedBytes = 0; // //>> ---- generate whole OutString (enter your code here) char* Ptr; uint16_t Len; if((IsFirstCall)&&(whttpd_preproc_get_req_param_value_ptr("gpio2=", &Ptr, &Len))){ //parameter found in parameters passed in Request-URI cb_gsg2_State = (Ptr[0]!='0'); PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2); GPIO_OUTPUT_SET(2, cb_gsg2_State); } sprintf(OutString, "%d", cb_gsg2_State); //<< ---- // whttpd_preproc_manage_cb_output(OutputData, OutString, &cb_gsg2_CopiedBytes, MaxBytes, RetBytes, RetDone); //output into OutputData (if MaxBytes is less than size of our data, manage subsequent chunked output throughout more calls of this tag callback function using global variable *_CopiedBytes) free(OutString); //free allocated memory return 0; //no error (don't abort tag preprocessing) }
void ICACHE_FLASH_ATTR clear_interrupt(){ //clear interrupt status uart0_sendStr("clear irq\n"); GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, GPIO_REG_READ(GPIO_STATUS_ADDRESS) ); as3935_chip_read(); switch(as3935.x3.a3.INT){ case IRQ_L: uart0_sendStr("as3935 lightning event \r\n"); //check if we are within treshold if(threshold_distance>as3935.x7.a7.DISTANCE){ //switch relay off GPIO_OUTPUT_SET(GPIO_ID_PIN(RELAY_PIN),0); //sqedule further checking state_machine=6; } break; case IRQ_D: uart0_sendStr("as3935 disturber detected \r\n"); break; case IRQ_NF: uart0_sendStr("as3935 noise lewel to high \r\n"); //todo: print to web page that we need to change settings break; } }
void user_init(void) { uart_div_modify(0, UART_CLK_FREQ / 115200); os_delay_us(500); printf("SDK version : %s\n", system_get_sdk_version()); mainqueue = xQueueCreate(10, sizeof(my_event_t)); connectToAp(); //setap("test", 4); init_led(); PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO5_U, FUNC_GPIO5); PIN_PULLUP_DIS(PERIPHS_IO_MUX_GPIO5_U); // disable pullodwn GPIO_REG_WRITE(GPIO_ENABLE_W1TS_ADDRESS,BIT5); GPIO_OUTPUT_SET(GPIO_ID_PIN(5), 1); char outbuffer[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; WS2812OutBuffer( outbuffer, 6 , 0); //Initialize the output. write_textwall_buffer(0, "BIER ", 5); xTaskCreate(simple_task, (signed char * )"simple_task", 256, &mainqueue, tskIDLE_PRIORITY, NULL); xTaskCreate(receive_udp, (signed char * )"test", 256, &mainqueue, tskIDLE_PRIORITY, NULL); timerHandle = xTimerCreate((signed char *) "Trigger", 50 / portTICK_RATE_MS, pdTRUE, NULL, timer_cb); if (timerHandle != NULL) { if (xTimerStart(timerHandle, 0) != pdPASS) { printf("%s: Unable to start Timer ...\n", __FUNCTION__); } } else { printf("%s: Unable to create Timer ...\n", __FUNCTION__); } }
int board_init(void) { /* adress of boot parameters */ gd->bd->bi_boot_params = 0x00000100; GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_IORST); GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_IORST); /* Setup GPIOs for PCI INTA */ GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_PCI1_INTA); GPIO_INT_ACT_LOW_SET(CONFIG_SYS_GPIO_PCI1_INTA); /* Setup GPIOs for 33MHz clock output */ GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_PCI_CLK); GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_EXTBUS_CLK); writel(0x011001FF, IXP425_GPIO_GPCLKR); udelay(533); GPIO_OUTPUT_SET(CONFIG_SYS_GPIO_IORST); ACTUX1_LED1(2); ACTUX1_LED2(2); ACTUX1_LED3(0); ACTUX1_LED4(0); ACTUX1_LED5(0); ACTUX1_LED6(0); ACTUX1_LED7(0); ACTUX1_HS(ACTUX1_HS_DCD); return 0; }
void ICACHE_FLASH_ATTR user_relay_set(int state) { if (relay_timer != 0 || state == relay_state) { return; } uint8 store_state = state; if (state < 0) { // Off for (-state) milliseconds then On relay_timer = setTimeout(user_relay_on, NULL, -state); state = 0; store_state = 1; } else if (state == 2) { // Toggle state = relay_state ? 0 : 1; store_state = state; } else if (state > 2) { // On for (state) milliseconds then Off relay_timer = setTimeout(user_relay_off, NULL, state); state = 1; store_state = 0; } GPIO_OUTPUT_SET(GPIO_ID_PIN(relay_hardware.gpio_id), state); relay_state = state; #if DEVICE == PLUG plug_led(PLUG_LED2, relay_state); emtr_relay_set(0, store_state); #endif }
///////////////////////////////////////////////////////////////// // wifi_event_handler_cb() - Callback function for WiFi events // ///////////////////////////////////////////////////////////////// void wifi_event_handler_cb(System_Event_t *event) { if (event == NULL) { return; } switch (event->event_id) // Switch on the event that brought us here { case EVENT_STAMODE_SCAN_DONE: // Once the scan is done, setupTimer(&blink_timer, 100/2, blink); // Blink at 10Hz break; case EVENT_STAMODE_CONNECTED: // Once we've connected (no IP yet), setupTimer(&blink_timer, 250/2, blink); // Blink at 4Hz break; case EVENT_STAMODE_GOT_IP: // If we're connected and received an IP, // Start the Phant post timer: setupTimer(&post_timer, POST_FREQUENCY, post); setupTimer(&blink_timer, 0, blink); // Turn blink off GPIO_OUTPUT_SET(LED_PIN, 1); // Turn LED on break; case EVENT_STAMODE_DISCONNECTED: // If disconnected, setupTimer(&blink_timer, 5000/2, blink); // blink every 5s break; default: break; } }
void ICACHE_FLASH_ATTR user_switch2_set(uint8 i, int state) { if (i >= SWITCH_COUNT || switch2_hardware[i].type != SWITCH2_RELAY) { return; } if (switch2_hardware[i].timer != 0 || state == switch2_hardware[i].state) { return; } uint8 store_state = state; if (state < 0) { // Off for (-state) milliseconds then On switch2_hardware[i].timer = setTimeout(user_switch2_on, &switch2_hardware[i], -state); state = 0; store_state = 1; } else if (state == 2) { // Toggle state = switch2_hardware[i].state == 0 ? 1 : 0; store_state = state; } else if (state > 2) { // On for (state) milliseconds then Off switch2_hardware[i].timer = setTimeout(user_switch2_off, &switch2_hardware[i], state); state = 1; store_state = 0; } GPIO_OUTPUT_SET(GPIO_ID_PIN(switch2_hardware[i].gpio.gpio_id), state); switch2_hardware[i].state = state; emtr_relay_set(i, store_state); }
LOCAL void ICACHE_FLASH_ATTR user_link_led_init(void) { PIN_FUNC_SELECT(SENSOR_LINK_LED_IO_MUX, SENSOR_LINK_LED_IO_FUNC); PIN_FUNC_SELECT(SENSOR_UNUSED_LED_IO_MUX, SENSOR_UNUSED_LED_IO_FUNC); GPIO_OUTPUT_SET(GPIO_ID_PIN(SENSOR_UNUSED_LED_IO_NUM), 0); }
void ICACHE_FLASH_ATTR switch2_down() { #if SWITCH2_DEBUG debug("SWITCH2: Down\n"); #endif // MOD_EMTR reset GPIO_OUTPUT_SET(GPIO_ID_PIN(switch2_reset_hardware.gpio_id), 0); }
// Perform the onewire reset function. We will wait up to 250uS for // the bus to come high, if it doesn't then it is broken or shorted // and we return a 0; // Returns 1 if a device asserted a presence pulse, 0 otherwise. uint32 ICACHE_FLASH_ATTR onewire_reset() { uint32 result; uint8 retries = 125; // Disable output on the pin. GPIO_DIS_OUTPUT(ONEWIRE_PIN); // Wait for the bus to get high (which it should because of the pull-up resistor). do { if (--retries == 0) { return 0; } os_delay_us(2); } while (!GPIO_INPUT_GET(ONEWIRE_PIN)); // Transmit the reset pulse by pulling the bus low for at least 480 us. GPIO_OUTPUT_SET(ONEWIRE_PIN, 0); os_delay_us(500); // Release the bus, and wait, then check for a presence pulse, which should start 15-60 us after the reset, and will last 60-240 us. // So 65us after the reset the bus must be high. GPIO_DIS_OUTPUT(ONEWIRE_PIN); os_delay_us(65); result = !GPIO_INPUT_GET(ONEWIRE_PIN); // After sending the reset pulse, the master (we) must wait at least another 480 us. os_delay_us(490); return result; }
void ICACHE_FLASH_ATTR LightSW_Quit(LightSW *lamp) { GPIO_OUTPUT_SET(lamp->_switchPin, FALSE); lamp->stateName = SEQUENCE_IDLE; lamp->operationStatus = OPERATION_STATUS__QUIT; INFO("Quit! > Idle\r\n"); }
void ICACHE_FLASH_ATTR ir_remote_init(uint16 gpio_pin_num, bool invert_logic_level) { _gpio_pin_num = gpio_pin_num; _logic_low = invert_logic_level; _logic_high = !_logic_low; _pwm_lvl = _logic_low; GPIO_ConfigTypeDef gpioCfg; gpioCfg.GPIO_Pin = BIT(_gpio_pin_num); gpioCfg.GPIO_Mode = GPIO_Mode_Output; gpioCfg.GPIO_Pullup = GPIO_PullUp_DIS; gpio_config(&gpioCfg); GPIO_OUTPUT_SET(_gpio_pin_num, _logic_low); portENTER_CRITICAL(); _xt_isr_attach(ETS_FRC_TIMER1_INUM, pwm_tim1_intr_handler); TM1_EDGE_INT_ENABLE(); _xt_isr_unmask((1 << ETS_FRC_TIMER1_INUM)); CLEAR_PERI_REG_MASK(FRC1_INT_ADDRESS, FRC1_INT_CLR_MASK); WRITE_PERI_REG(FRC1_CTRL_ADDRESS, CLOCK_DIV_256 | FRC1_ENABLE_TIMER | TM_EDGE_INT); WRITE_PERI_REG(FRC1_LOAD_ADDRESS, 0); portEXIT_CRITICAL(); }
int board_init(void) { gd->bd->bi_arch_number = MACH_TYPE_DVLHOST; /* adress of boot parameters */ gd->bd->bi_boot_params = 0x00000100; /* Setup GPIOs used as output */ GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_WDGTRIGGER); GPIO_OUTPUT_SET(CONFIG_SYS_GPIO_DLAN_PAIRING); GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_PCIRST); /* * LED latch enable and watchdog enable are tied to the same GPIO, * so we need to trigger the watchdog if we want to enable the LEDs. */ #ifdef CONFIG_HW_WATCHDOG GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_WDG_LED_EN); #else GPIO_OUTPUT_SET(CONFIG_SYS_GPIO_WDG_LED_EN); #endif GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_WDGTRIGGER); GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_DLAN_PAIRING); GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_WDG_LED_EN); GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_PCIRST); /* Setup GPIOs for Interrupt inputs */ GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_BTN_WLAN); GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_BTN_PAIRING); GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_BTN_RESET); GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_IRQA); GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_IRQB); /* Setup GPIO's for 33MHz clock output */ GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_PCI_CLK); GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_EXTBUS_CLK); writel(0x01FF01FF, IXP425_GPIO_GPCLKR); /* turn off all LEDs */ writew(0x0000, DVLHOST_LED_LATCH); udelay(533); GPIO_OUTPUT_SET(CONFIG_SYS_GPIO_PCIRST); return 0; }
int board_init (void) { gd->bd->bi_arch_number = MACH_TYPE_ACTUX2; /* adress of boot parameters */ gd->bd->bi_boot_params = 0x00000100; GPIO_OUTPUT_ENABLE (CONFIG_SYS_GPIO_IORST); GPIO_OUTPUT_ENABLE (CONFIG_SYS_GPIO_ETHRST); GPIO_OUTPUT_ENABLE (CONFIG_SYS_GPIO_DSR); GPIO_OUTPUT_ENABLE (CONFIG_SYS_GPIO_DCD); GPIO_OUTPUT_CLEAR (CONFIG_SYS_GPIO_IORST); GPIO_OUTPUT_CLEAR (CONFIG_SYS_GPIO_ETHRST); GPIO_OUTPUT_CLEAR (CONFIG_SYS_GPIO_DSR); GPIO_OUTPUT_SET (CONFIG_SYS_GPIO_DCD); /* Setup GPIO's for Interrupt inputs */ GPIO_OUTPUT_DISABLE (CONFIG_SYS_GPIO_DBGINT); GPIO_OUTPUT_DISABLE (CONFIG_SYS_GPIO_ETHINT); /* Setup GPIO's for 33MHz clock output */ GPIO_OUTPUT_ENABLE (CONFIG_SYS_GPIO_PCI_CLK); GPIO_OUTPUT_ENABLE (CONFIG_SYS_GPIO_EXTBUS_CLK); *IXP425_GPIO_GPCLKR = 0x011001FF; /* CS1: IPAC-X */ *IXP425_EXP_CS1 = 0x94d10013; /* CS5: Debug port */ *IXP425_EXP_CS5 = 0x9d520003; /* CS6: HW release register */ *IXP425_EXP_CS6 = 0x81860001; /* CS7: LEDs */ *IXP425_EXP_CS7 = 0x80900003; udelay (533); GPIO_OUTPUT_SET (CONFIG_SYS_GPIO_IORST); GPIO_OUTPUT_SET (CONFIG_SYS_GPIO_ETHRST); ACTUX2_LED1 (1); ACTUX2_LED2 (0); ACTUX2_LED3 (0); ACTUX2_LED4 (0); return 0; }
void pwm_tim1_intr_handler() { CLEAR_PERI_REG_MASK(FRC1_INT_ADDRESS, FRC1_INT_CLR_MASK); if (_pwm_enable) { GPIO_OUTPUT_SET(_gpio_pin_num, _pwm_lvl); _pwm_lvl ^= 1; } else if (_pwm_lvl == _logic_high) { _pwm_lvl = _logic_low; GPIO_OUTPUT_SET(_gpio_pin_num, _pwm_lvl); } WRITE_PERI_REG(FRC1_LOAD_ADDRESS, _frc1_ticks); }
void ICACHE_FLASH_ATTR user_link_led_timer_init(void) { link_start_time = system_get_time(); os_timer_disarm(&link_led_timer); os_timer_setfn(&link_led_timer, (os_timer_func_t *)user_link_led_timer_cb, NULL); os_timer_arm(&link_led_timer, 50, 1); link_led_level = 0; GPIO_OUTPUT_SET(GPIO_ID_PIN(SENSOR_LINK_LED_IO_NUM), link_led_level); }
static inline void apa102_send_byte(uint32_t data_pin, uint32_t clock_pin, uint8_t byte) { int i; for (i = 0; i < 8; i++) { if (byte & 0x80) { GPIO_OUTPUT_SET(data_pin, PLATFORM_GPIO_HIGH); // Set pin high } else { GPIO_OUTPUT_SET(data_pin, PLATFORM_GPIO_LOW); // Set pin low } GPIO_OUTPUT_SET(clock_pin, PLATFORM_GPIO_HIGH); // Set pin high byte <<= 1; NOP; NOP; GPIO_OUTPUT_SET(clock_pin, PLATFORM_GPIO_LOW); // Set pin low NOP; NOP; } }
static void ICACHE_FLASH_ATTR ost_loop(os_event_t *events) { GPIO_OUTPUT_SET(5,ledState); ledState = ~ledState; os_printf("Read...\n"); os_delay_us(1000000); system_os_post(user_procTaskPrio, 0, 0 ); }
LOCAL void ICACHE_FLASH_ATTR dht22_cb(void *arg) { struct dht_sensor_data* r = DHTRead(); int tempLength=0; int humLength=0; float lastTemp = r->temperature; float lastHum = r->humidity; if(r->success&&lastTemp>-30&&lastHum>0) { //TRANSFORMATION HERE console_printf("DHT22/Temperature: %d.%d *C, Humidity: %d.%d %%\r\n", (int)(lastTemp),(int)((lastTemp - (int)lastTemp)*100), (int)(lastHum),(int)((lastHum - (int)lastHum)*100)); os_sprintf(DHT22_Temperature,"%d.%d", (int)(lastTemp),(int)((lastTemp - (int)lastTemp)*100)); os_sprintf(DHT22_Humidity,"%d.%d", (int)(lastHum),(int)((lastHum - (int)lastHum)*100)); if(lastTemp>=0) { if(lastTemp>9) tempLength=4; else tempLength=3; } else tempLength=5; // assumption - bathroom temperature should not fall under -9 :P if(lastHum>9) humLength=2; else if (lastHum==100) humLength=3; else humLength=1; // MQTT PUBLISH HERE MQTT_Publish(&mqttClient,DHT22_MQTT_Temperature,DHT22_Temperature,tempLength,0,0); MQTT_Publish(&mqttClient,DHT22_MQTT_Humidity,DHT22_Humidity,humLength,0,0); // MANUAL MODE LOGICS HERE if (dDEVICE_MODE){ // maintain currently set humidity if(lastHum<dBR_HUMIDITY_SET&&GPIO_INPUT_GET(PIN_GPIO5)&&!GPIO_INPUT_GET(PIN_GPIO13)) { GPIO_OUTPUT_SET(PIN_GPIO5, 0); } else if ((lastHum>dBR_HUMIDITY_SET+7)&&!GPIO_INPUT_GET(PIN_GPIO5)) { GPIO_OUTPUT_SET(PIN_GPIO5,1); } // maintain currently set bathroom temperature if(lastTemp>=dBR_TEMP_ROOM_SET&&GPIO_INPUT_GET(PIN_GPIO12)){ GPIO_OUTPUT_SET(PIN_GPIO12,0); } else if ((lastTemp<dBR_TEMP_ROOM_SET-1)&&!GPIO_INPUT_GET(PIN_GPIO12)) { GPIO_OUTPUT_SET(PIN_GPIO12,1); } } } else { console_printf("Error reading temperature and humidity\r\n"); } }