Пример #1
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();
  }
 
}
Пример #2
0
static void radio_setup()
{
    // RF 231
    // Set IRQ (PC4) as input IRQ
    gpio_set_input(GPIO_C, GPIO_PIN_4);
    afio_select_exti_pin(EXTI_LINE_Px4, AFIO_PORT_C);
    nvic_enable_interrupt_line(NVIC_IRQ_LINE_EXTI4);

    // Set DIG2 (PB0) as Timer 3 channel 3 input capture
    // Configure the Timer Capture pins
    gpio_set_input(GPIO_B, GPIO_PIN_0);

    // Initialize the radio to put it in Sleep State
    rf2xx_init(rf231);
}
Пример #3
0
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();
}
Пример #4
0
bool spi_init(SPI_t* port,
              bool lsb_first,
              uint8_t spi_mode,
              uint32_t max_clock_speed_hz,
              SpiControl* out_control) {
  if (max_clock_speed_hz < CHIP_SPI_MIN_CLOCK_SPEED_HZ)
        return false;

  chip_spi_enable(false);

  gpio_set_output(chip_spi_mosi_pin(port));
  gpio_set_output(chip_spi_sck_pin(port));
  gpio_set_input(chip_spi_miso_pin(port));

  chip_spi_set_clock_speed(port, max_clock_speed_hz);

  chip_spi_set_operating_params(port, lsb_first, true, spi_mode);

  chip_spi_enable(true);

  out_control->port = port;
  out_control->active_transfer = NULL;

  return true;
}
Пример #5
0
static void power_setup()
{
    /*
     * Configure the multiplexer:
     *      EN: PC6
     *      A0: PC9
     *      A1: PC10
     */
    adg759_config(&ina_mux, GPIO_TYPE_PUSH_PULL);
    adg759_enable(&ina_mux);
    adg759_select(&ina_mux, ADG759_INPUT_1);

    log_printf("Configuring INA226...\n");

    // Select PC0 as input interrupt (ALERT)
    gpio_set_input(GPIO_C, GPIO_PIN_0);
    afio_select_exti_pin(EXTI_LINE_Px0, AFIO_PORT_C);
    nvic_enable_interrupt_line(NVIC_IRQ_LINE_EXTI0);

    // Configure the INA226, then initialize
    ina226_init(I2C_1, 0x80, EXTI_LINE_Px0);

    // Initial calibration
    ina226_calibrate(1, 0.1);

    // Configure the fiteco lib
    fiteco_lib_gwt_set_config(&gwt_config);
}
Пример #6
0
/*----------------------------------------------------------------------------*
write one byte on 1 wire.
Parameters:
   bytes to write.
Returns:
 *----------------------------------------------------------------------------*/
void
owr_writeb(unsigned byte)
{
  int i;

  for(i = 0; i < 8; i++) {
    if(byte & 0x01) {
      gpio_set_output(GPIO_1WR);
      micro_delay(tW1L);
      gpio_set_input(GPIO_1WR);
      micro_delay(tSLOT - tW1L);
    } else {
      gpio_set_output(GPIO_1WR);
      micro_delay(tW0L);
      gpio_set_input(GPIO_1WR);
      micro_delay(tSLOT - tW0L);
    }
    byte >>= 1;
  }
}
Пример #7
0
void gpio_set_direction(const char GPIO[], enum gpio_direction direction) {
    if(direction == OUTPUT) {
        gpio_set_output(GPIO);
    }
    else if(ANALOG){
        gpio_set_analog(GPIO);
    }
    else {
        gpio_set_input(GPIO);
    }
}
Пример #8
0
void notmain() {
  led_init();
  gpio_init();
  gfx_init();
  
  gpio_set_input(GPIO_PIN23); 
  gpio_set_pullup(GPIO_PIN23); 
  gpio_set_input(GPIO_PIN24); 
  gpio_set_pullup(GPIO_PIN24); 

  string[0] = 'Z';
  string[1] = 0;
  len = 1;
  gfx_draw_letter(0xFFFFFFFF, 200, 20, '!');
  
  while (1) {
    /* Code removed as it's part of assignment 6. */
  }

}
Пример #9
0
/*----------------------------------------------------------------------------*
 reset the 1 wire.
Parameters:
Returns:
  1 if presence detect.
 *----------------------------------------------------------------------------*/
int
owr_reset(void)
{
  int result;

  cli();
  gpio_set_output(GPIO_1WR);
  gpio_set_off(GPIO_1WR);
  micro_delay(tRSTL);
  gpio_set_input(GPIO_1WR);
  micro_delay(tMSP);
  result = gpio_get(GPIO_1WR);
  micro_delay(tRSTL);
  sei();
  return !result;
}
Пример #10
0
/*
 * Disable all interrupts except  GPIO interrupt 0, which is for pins 0-31. This
 * interrupt is IRQ 49, so bit 17 of the second register (BCM2835 ARM
 * Peripherals Manual, top of page 113).
 */
void kdriver_init() {
  gpio_init();

  // Ensure all interrupts are disabled.
  PUT32(RPI_INT_DISABLE_1, 0xFFFFFFFF);
  PUT32(RPI_INT_DISABLE_2, 0xFFFFFFFF);

  // We'll be hooking up a button to Pin 23, so set it up appropriately.
  gpio_set_input(GPIO_PIN23);
  gpio_set_pullup(GPIO_PIN23); 
  gpio_detect_falling_edge(GPIO_PIN23);

  // Enable GPIO interrupt 0
  PUT32(RPI_INT_ENABLE_2, 0x00100000);

  // Enable interrupts
  system_enable_interrupts();
}
Пример #11
0
/*----------------------------------------------------------------------------*
read one byte on 1 wire
Parameters:
Returns:
  value.
 *----------------------------------------------------------------------------*/
unsigned
owr_readb(void)
{
  unsigned result = 0;
  int i;

  for(i = 0; i < 8; i++) {
    result >>= 1;
    gpio_set_output(GPIO_1WR);
    micro_delay(tRL);
    gpio_set_input(GPIO_1WR);
    micro_delay(tMSR);
    if(gpio_get(GPIO_1WR)) {
      result |= 0x80;
    }
    micro_delay(tSLOT - tRL);
  }
  return result;
}
Пример #12
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;
}
Пример #13
0
void spi_set_high_impedance(SPI_t* port) {
  gpio_set_input(chip_spi_mosi_pin(port));
  gpio_set_input(chip_spi_sck_pin(port));
  gpio_set_input(chip_spi_miso_pin(port));
}