static void clear_echo_standby_mode() { echo_standby_turn_on_ata(); echo_standby_turn_on_eth(); /* turn on wlan power */ gpio_set_high(GPIO_WLAN_PD); /* turn of LCD backlight */ gpio_set_high(GPIO_LCD_BACKLIGHT); /* set echo stand by led to green */ gpio_set_as_output(GPIO_LED_ECHOSTDBY, 1); }
void gpio_set_level(uint32_t gpio, uint32_t pin, bool level) { if(level) gpio_set_high(gpio, pin); else gpio_set_low(gpio, pin); }
void gpio_write(const char GPIO[], const bool STATE) { if(STATE) { gpio_set_high(GPIO); } else { gpio_set_low(GPIO); } }
void ioapi_output_high_body( uint8_t pin_number ) { // ASSERT( gpio_is_it_output( pin_number) == SC_TRUE); gpio_set_high(pin_number); }
static int leddev_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) { unsigned int cmd_buf[10]; switch (cmd) { case GPIO_GET_VALUE: if (copy_from_user (cmd_buf, (void *) arg, 4)) return -EFAULT; cmd_buf[1] = gpio_get_value (cmd_buf[0]); DBG_GPIO_FUNCTION (cmd_buf[0], cmd_buf[1], "gpio_get_value"); if (copy_to_user ((unsigned *) arg, &cmd_buf[1], 4)) return -EFAULT; break; case GPIO_SET_HIGH: if (copy_from_user (cmd_buf, (void *) arg, 4)) return -EFAULT; DBG_GPIO_FUNCTION (cmd_buf[0], -1, "gpio_set_high"); gpio_set_high (cmd_buf[0]); break; case GPIO_SET_LOW: if (copy_from_user (cmd_buf, (void *) arg, 4)) return -EFAULT; DBG_GPIO_FUNCTION (cmd_buf[0], -1, "gpio_set_low"); gpio_set_low (cmd_buf[0]); break; case GPIO_SET_AS_INPUT: if (copy_from_user (cmd_buf, (void *) arg, 4)) return -EFAULT; DBG_GPIO_FUNCTION (cmd_buf[0], -1, "gpio_set_as_input"); gpio_set_as_input (cmd_buf[0]); break; case GPIO_SET_AS_OUTPUT: if (copy_from_user (cmd_buf, (void *) arg, 4*2)) return -EFAULT; DBG_GPIO_FUNCTION (cmd_buf[0], cmd_buf[1], "gpio_set_as_output"); gpio_set_as_output (cmd_buf[0], cmd_buf[1]); break; case GPIO_SET_AS_FUNCTION: if (copy_from_user (cmd_buf, (void *) arg, 4)) return -EFAULT; DBG_GPIO_FUNCTION (cmd_buf[0], -1, "gpio_set_as_function"); gpio_set_as_function (cmd_buf[0]); break; case ECOLED_SET_VALUE: if (copy_from_user (&ecoStandbyValue, (void *) arg, sizeof(ecoStandbyValue))) return -EFAULT; gpio_set_as_output (GPIO_SPI1_SCK, ecoStandbyValue); break; case ECOLED_GET_VALUE: if (copy_to_user ((unsigned *) arg, &ecoStandbyValue, sizeof(ecoStandbyValue))) return -EFAULT; break; case IOCTL_FAN_CTL: #if defined (CONFIG_PNX0106_W6) if (copy_from_user (&fan_ctl_mode, (void *) arg, sizeof(fan_ctl_mode))) return -EFAULT; gpio_set_as_output (GPIO_IEEE1394_D4, (fan_ctl_mode == 0) ? 0 : 1); // 0 == fan off #else /* GPIO_IEEE1394_D4 is not the correct GPIO on non-w6 platforms... */ printk ("IOCTL_FAN_CTL: hardcoded gpio pin definition supports W6 platforms only...\n"); return -ENODEV; #endif break; case IOCTL_MISC_COUNTRY_DETECT: { unsigned int w_country_code; unsigned int w_ad_value; adcdrv_set_mode (1); // may be initialized twice, anyway should be ok gpio_set_as_input (GPIO_V2); // B8--Version_2 gpio_set_as_input (GPIO_V3); // L16--Version_3 w_country_code = (gpio_get_value (GPIO_V2)) << 1; w_country_code |= (gpio_get_value (GPIO_V3)) << 0; w_ad_value = adc_read (ADC_CHANNEL_3); w_country_code |= (w_ad_value << 16); if (copy_to_user ((unsigned *) arg, &w_country_code, sizeof(w_country_code))) return -EFAULT; printk ("IOCTL_MISC_COUNTRY_DETECT called\n"); break; } case IOCTRL_INIT_RDS_TIMER: init_rds_check_timer(); break; case IOCTRL_READ_RDS_MSG_BLOCK: //printk("\n rds msg read blocked "); interruptible_sleep_on (&read_rds_msg_wq); break; case IOCTL_MISC_GET_NTC: { int ntc_val; ntc_val = adc_get_value (ADC_CHANNEL_2); // ADC10B_GPA2, pin U4 if (copy_to_user ((int *) arg, &ntc_val, 4)) return -EFAULT; break; } case IOCTL_MISC_WAKEUP_THREAD: { int pid; struct task_struct *p; if (copy_from_user (&pid, (void *) arg, 4)) return -EFAULT; printk ("Try to wake up pid:%d\n", pid); if ((pid > 0) && (p = find_task_by_pid (pid))) wake_up_process (p); break; } default: return -EFAULT; } return 0; }
bool dht22_read_data(struct dht22 *dht, float *temp, float *hum, struct error *err) { uint32_t count = 0; uint32_t threshold = 0; uint32_t pulseCounts[DHT_PULSES*2] = {0}; gpio_set_output(dht->pin); gpio_max_priority(); gpio_set_high(dht->pin); gpio_sleep_millis(500); gpio_set_low(dht->pin); gpio_wait_millis(20); gpio_set_input(dht->pin); /* * Need a very short delay before reading pins or else value * is sometimes still low. */ for (volatile uint8_t i = 0; i < 50; ++i) {} /* Wait for DHT to pull pin low. */ while (gpio_read(dht->pin)) if (++count >= DHT_MAXCOUNT) { gpio_default_priority(); strcpy(err->message, "Error timeout."); return false; } /* Record pulse widths for the expected result bits. */ for (uint8_t i = 0; i < DHT_PULSES*2; i += 2) { while (!gpio_read(dht->pin)) if (++pulseCounts[i] >= DHT_MAXCOUNT) { gpio_default_priority(); strcpy(err->message, "Error timeout."); return false; } while (gpio_read(dht->pin)) if (++pulseCounts[i+1] >= DHT_MAXCOUNT) { gpio_default_priority(); strcpy(err->message, "Error timeout."); return false; } } gpio_default_priority(); for (uint8_t i = 2; i < DHT_PULSES*2; i += 2) threshold += pulseCounts[i]; threshold /= DHT_PULSES-1; /* Interpret each high pulse as a 0 or 1 by comparing it to the 50us reference. * If the count is less than 50us it must be a ~28us 0 pulse, and if it's higher * then it must be a ~70us 1 pulse. */ for (uint8_t i = 3; i < DHT_PULSES*2; i += 2) { uint8_t index = (i-3)/16; dht->data[index] <<= 1; if (pulseCounts[i] >= threshold) dht->data[index] |= 1; } if (dht->data[4] == ((dht->data[0] + dht->data[1] + dht->data[2] + dht->data[3]) & 0xFF)) { *hum = (dht->data[0] * 256 + dht->data[1]) / 10.0f; *temp = ((dht->data[2] & 0x7F) * 256 + dht->data[3]) / 10.0f; if (dht->data[2] & 0x80) *temp *= -1.0f; } else strcpy(err->message, "Can not read data."); strcpy(err->message, ""); return true; }