static void
mousebtn_poll(void *arg)
{
	struct mousebtn_softc *sc = (struct mousebtn_softc *)arg;
	uint32_t buttons = 0;
	int s;
	int left;
	int right;

	mutex_enter(&sc->sc_lock);

	left = !gpio_pin_read(sc->sc_gpio, &sc->sc_map, MOUSEBTN_PIN_LEFT);
	right = !gpio_pin_read(sc->sc_gpio, &sc->sc_map, MOUSEBTN_PIN_RIGHT);
	buttons = (right << 2) | left;

	if (sc->sc_buttons != buttons) {
		s = spltty();
		wsmouse_input(sc->sc_wsmousedev, buttons, 0, 0, 0, 0,
		    WSMOUSE_INPUT_DELTA);
		sc->sc_buttons = buttons;
		splx(s);
	}

	mutex_exit(&sc->sc_lock);

#if defined(MOUSEBTN_POLLING)
	if (sc->sc_enabled)
		callout_reset(&sc->sc_c, POLLRATE, mousebtn_poll, sc);
#endif
	return;
}
Exemple #2
0
unsigned char leds_arch_get(void)
{
    int l0 = gpio_pin_read(LED_0_PORT, LED_0_PIN);
    int l1 = gpio_pin_read(LED_1_PORT, LED_1_PIN);
    int l2 = gpio_pin_read(LED_2_PORT, LED_2_PIN);

    return (l0 ? LED_0 : 0) | (l1 ? LED_1 : 0) | (l2 ? LED_2 : 0);
}
static inline enum hw_board_id read_board_id(void)
{
    enum hw_board_id bid;

    bid = MAKE_HW_BOARD_ID(gpio_pin_read(40), 
                            gpio_pin_read(41),
                            gpio_pin_read(42));
    return bid;
}
Exemple #4
0
void notmain() {
  led_init();
  gpio_init();
  gfx_init();

  unsigned int index = 0;
  char line[60];
  line[0] = 0;
  
  gpio_set_input(GPIO_PIN23);
  gpio_set_input(GPIO_PIN24);
  gpio_set_pullup(GPIO_PIN23);
  gpio_set_pullup(GPIO_PIN24);
  //  while (1) {}
  while (1) {
    wait_for_clock();
    line[index] = '+';
    line[++index] = 0;
    gfx_clear();
    gfx_draw_string(0xFFFFFFFF, 20, 20, "Button pushes: ");
    gfx_draw_string(0xFFFFFFFF, 210, 20, line);
    gfx_draw();
  }
  
  while (1) {
    unsigned char ch = 0;
    int pinval;

    wait_for_clock();
    pinval = gpio_pin_read(GPIO_PIN24);
    if (pinval != 0) {
      //continue;
    }    

    int i;
    for (i = 0; i < 8; i++) {
      wait_for_clock();
      ch |= gpio_pin_read(GPIO_PIN24) << i;
    }

    wait_for_clock();
    wait_for_clock();

    ch = 'z'; //lookup_table[ch];
    if (index < LINE_SIZE) {
      line[index] = ch;
      line[index++] = 0;
    }
    gfx_clear();
    gfx_draw_string(0xFFFFFFFF, 20, 20, line);
    gfx_draw();
  }
 
}
Exemple #5
0
uint32_t
gpioiic_bb_read_bits(void *cookie)
{
	struct gpioiic_softc *sc = cookie;
	uint32_t bits = 0;

	if (gpio_pin_read(sc->sc_gpio, &sc->sc_map,
	    sc->sc_pin_sda) == GPIO_PIN_HIGH)
		bits |= GPIOIIC_SDA;
	if (gpio_pin_read(sc->sc_gpio, &sc->sc_map,
	    sc->sc_pin_scl) == GPIO_PIN_HIGH)
		bits |= GPIOIIC_SCL;

	return bits;
}
Exemple #6
0
/**
 * @brief Measure duration of signal send by sensor
 *
 * @param drv_data Pointer to the driver data structure
 * @param signal_val Value of signal being measured
 *
 * @return duration in usec of signal being measured,
 *         -1 if duration exceeds DHT_SIGNAL_MAX_WAIT_DURATION
 */
static s8_t dht_measure_signal_duration(struct dht_data *drv_data,
					  u32_t signal_val)
{
	u32_t val;
	u32_t elapsed_cycles;
	u32_t max_wait_cycles = (u32_t)(
		(u64_t)DHT_SIGNAL_MAX_WAIT_DURATION *
		(u64_t)sys_clock_hw_cycles_per_sec /
		(u64_t)USEC_PER_SEC
	);
	u32_t start_cycles = k_cycle_get_32();

	do {
		gpio_pin_read(drv_data->gpio, CONFIG_DHT_GPIO_PIN_NUM, &val);
		elapsed_cycles = k_cycle_get_32() - start_cycles;

		if (elapsed_cycles >= max_wait_cycles) {
			return -1;
		}
	} while (val == signal_val);

	return (u64_t)elapsed_cycles *
	       (u64_t)USEC_PER_SEC /
	       (u64_t)sys_clock_hw_cycles_per_sec;
}
void platform_periph_setup()
{
    // Test PC8, if 0 then SLP_TR is bound
    gpio_set_input(GPIO_C, GPIO_PIN_8); // Red
    gpio_config_pull_up_down(GPIO_C, GPIO_PIN_8, GPIO_PULL_UP);

    if (gpio_pin_read(GPIO_C, GPIO_PIN_8) == 0)
    {
        log_info("SLP_TR to timer effective!");
        al04_has_slptr_on_timer = 1;
    }

    // Disable pull up
    gpio_set_analog(GPIO_C, GPIO_PIN_8);
    gpio_config_pull_up_down(GPIO_C, GPIO_PIN_8, GPIO_PULL_DISABLED);

    // Initialize the radio chip
    radio_setup();

    // Setup the feedback battery
    vbat_setup();

    // Initialize the amplifier
    amp_setup();
}
Exemple #8
0
void main(void)
{
	struct device *gpiob;

	printk("Press the user defined button on the board\n");
	gpiob = device_get_binding(PORT);
	if (!gpiob) {
		printk("error\n");
		return;
	}

	gpio_pin_configure(gpiob, PIN,
			   GPIO_DIR_IN | GPIO_INT |  PULL_UP | EDGE);

	gpio_init_callback(&gpio_cb, button_pressed, BIT(PIN));

	gpio_add_callback(gpiob, &gpio_cb);
	gpio_pin_enable_callback(gpiob, PIN);

	while (1) {
		u32_t val = 0;

		gpio_pin_read(gpiob, PIN, &val);
		k_sleep(SLEEP_TIME);
	}
}
Exemple #9
0
static int i2c_gpio_get_sda(void *io_context)
{
	struct i2c_gpio_context *context = io_context;
	u32_t state = 1; /* Default high as that would be a NACK */

	gpio_pin_read(context->gpio, context->sda_pin, &state);
	return state;
}
Exemple #10
0
int
gpioow_bb_get(void *arg)
{
	struct gpioow_softc *sc = arg;

	return (gpio_pin_read(sc->sc_gpio, &sc->sc_map, GPIOOW_PIN_DATA) ==
	    GPIO_PIN_HIGH ? 1 : 0);
}
Exemple #11
0
static bool eswifi_spi_cmddata_ready(struct eswifi_spi_data *spi)
{
	int value;

	gpio_pin_read(spi->dr.dev, spi->dr.pin, &value);

	return value ? true : false;
}
static void
n900prxmty_refresh(void *v)
{
	struct n900prxmty_softc *sc = v;
	int i;
	int event;

	i = gpio_pin_read(sc->sc_gpio, &sc->sc_map, N900PRXMTY_PIN_INPUT);
	event = (i == GPIO_PIN_HIGH)
		? PSWITCH_EVENT_PRESSED : PSWITCH_EVENT_RELEASED;

	/* report the event */
	sysmon_pswitch_event(&sc->sc_smpsw, event);
}
static void
gpiopwm_pulse(void *arg)
{
	struct gpiopwm_softc *sc;

	sc = arg;
	if (gpio_pin_read(sc->sc_gpio, &sc->sc_map, 0) == GPIO_PIN_HIGH) {
		gpio_pin_write(sc->sc_gpio, &sc->sc_map, 0, GPIO_PIN_LOW);
		callout_schedule(&sc->sc_pulse, sc->sc_ticks_off);
	} else {
		gpio_pin_write(sc->sc_gpio, &sc->sc_map, 0, GPIO_PIN_HIGH);
		callout_schedule(&sc->sc_pulse, sc->sc_ticks_on);
	}
}
static void
n900audjck_refresh(void *v)
{
	struct n900audjck_softc *sc = v;
	int i;
	int event;

	i = gpio_pin_read(sc->sc_gpio, &sc->sc_map, N900AUDJCK_PIN_INPUT);
	event = (i == GPIO_PIN_HIGH)
		? PSWITCH_EVENT_RELEASED : PSWITCH_EVENT_PRESSED;

	/* crude way to avoid duplicate events */
	if(event == sc->sc_state)
		return;
	sc->sc_state = event;

	/* report the event */
	sysmon_pswitch_event(&sc->sc_smpsw, event);
}
Exemple #15
0
void main(void)
{
	struct device *gpiob;

	gpiob = device_get_binding(PORT);

	gpio_pin_configure(gpiob, PIN,
			GPIO_DIR_IN | GPIO_INT
			| EDGE
			| PULL_UP);

	gpio_init_callback(&gpio_cb, button_pressed, BIT(PIN));

	gpio_add_callback(gpiob, &gpio_cb);
	gpio_pin_enable_callback(gpiob, PIN);

	while (1) {
		int val = 0;

		gpio_pin_read(gpiob, PIN, &val);
		PRINT("GPIO val: %d\n", val);
		task_sleep(MSEC(500));
	}
}
Exemple #16
0
void wait_for_clock() {
  led_toggle();
  while (gpio_pin_read(GPIO_PIN23) == 0) {}
  while (gpio_pin_read(GPIO_PIN23) == 1) {}
}
Exemple #17
0
static int bt_spi_send(struct net_buf *buf)
{
	u8_t header[5] = { SPI_WRITE, 0x00,  0x00,  0x00,  0x00 };
	u32_t pending;

	/* Buffer needs an additional byte for type */
	if (buf->len >= SPI_MAX_MSG_LEN) {
		BT_ERR("Message too long");
		return -EINVAL;
	}

	/* Allow time for the read thread to handle interrupt */
	while (true) {
		gpio_pin_read(irq_dev, GPIO_IRQ_PIN, &pending);
		if (!pending) {
			break;
		}
		k_sleep(1);
	}

	k_sem_take(&sem_busy, K_FOREVER);

	switch (bt_buf_get_type(buf)) {
	case BT_BUF_ACL_OUT:
		net_buf_push_u8(buf, HCI_ACL);
		break;
	case BT_BUF_CMD:
		net_buf_push_u8(buf, HCI_CMD);
		break;
	default:
		BT_ERR("Unsupported type");
		k_sem_give(&sem_busy);
		return -EINVAL;
	}

	/* Poll sanity values until device has woken-up */
	do {
#if defined(CONFIG_BLUETOOTH_SPI_BLUENRG)
		gpio_pin_write(cs_dev, GPIO_CS_PIN, 1);
		gpio_pin_write(cs_dev, GPIO_CS_PIN, 0);
#endif /* CONFIG_BLUETOOTH_SPI_BLUENRG */
		spi_transceive(spi_dev, header, 5, rxmsg, 5);

		/*
		 * RX Header (rxmsg) must contain a sanity check Byte and size
		 * information.  If it does not contain BOTH then it is
		 * sleeping or still in the initialisation stage (waking-up).
		 */
	} while (rxmsg[STATUS_HEADER_READY] != READY_NOW ||
		 (rxmsg[1] | rxmsg[2] | rxmsg[3] | rxmsg[4]) == 0);

	/* Transmit the message */
	do {
		spi_transceive(spi_dev, buf->data, buf->len, rxmsg, buf->len);
	} while (rxmsg[0] == 0);

#if defined(CONFIG_BLUETOOTH_SPI_BLUENRG)
	/* Deselect chip */
	gpio_pin_write(cs_dev, GPIO_CS_PIN, 1);
#endif /* CONFIG_BLUETOOTH_SPI_BLUENRG */
	k_sem_give(&sem_busy);

	spi_dump_message("TX:ed", buf->data, buf->len);

#if defined(CONFIG_BLUETOOTH_SPI_BLUENRG)
	/*
	 * Since a RESET has been requested, the chip will now restart.
	 * Unfortunately the BlueNRG will reply with "reset received" but
	 * since it does not send back a NOP, we have no way to tell when the
	 * RESET has actually taken palce.  Instead, we use the vendor command
	 * EVT_BLUE_INITIALIZED as an indication that it is safe to proceed.
	 */
	if (bt_spi_get_cmd(buf->data) == BT_HCI_OP_RESET) {
		k_sem_take(&sem_initialised, K_FOREVER);
	}
#endif /* CONFIG_BLUETOOTH_SPI_BLUENRG */

	net_buf_unref(buf);

	return 0;
}