Beispiel #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();
  }
 
}
Beispiel #2
0
void keyboard_init(void) {
  gpio_init();
  // Ensure all interrupts are disabled.
  PUT32(RPI_INT_DISABLE_1, 0xFFFFFFFF);
  PUT32(RPI_INT_DISABLE_2, 0xFFFFFFFF);

  gpio_set_function(CLK, GPIO_FUNC_INPUT);
  gpio_set_pullup(CLK);
  gpio_detect_falling_edge(CLK);

  gpio_set_function(DATA, GPIO_FUNC_INPUT);
  gpio_set_pullup(DATA);

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

  // Enable interrupts
  system_enable_interrupts(); 
}
Beispiel #3
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. */
  }

}
Beispiel #4
0
void act_linearAct_Init(void)
{
#if act_linearAct_USEEEPROM==1
	if (EEDATA_OK)
	{
	  ///TODO: Use stored data to set initial values for the module
	  pulses = eeprom_read_word(EEDATA16.pulses_ee);
	  min = eeprom_read_word(EEDATA16.min_ee);
	  low = eeprom_read_word(EEDATA16.low_ee);
	  high = eeprom_read_word(EEDATA16.high_ee);
	  max = eeprom_read_word(EEDATA16.max_ee);
	} else
	{	//The CRC of the EEPROM is not correct, store default values and update CRC
	  eeprom_write_word_crc(EEDATA16.pulses_ee, 1200, WITHOUT_CRC);
	  eeprom_write_word_crc(EEDATA16.min_ee, 300, WITHOUT_CRC);
	  eeprom_write_word_crc(EEDATA16.low_ee, 815, WITHOUT_CRC);
	  eeprom_write_word_crc(EEDATA16.high_ee, 5600, WITHOUT_CRC);
	  eeprom_write_word_crc(EEDATA16.max_ee, 6100, WITHOUT_CRC);
	  EEDATA_UPDATE_CRC;
	}
#else	
	// Only for testing/debugging...
	pulses = 1200;
	min = 300;
	low = 815;
	high = 5600;
	max = 6100;
#endif
	
	// PD5 (EXP_G) is used as Timer1 input. Hardwired, no move possible!
	gpio_set_in(EXP_G);
	gpio_set_pullup(EXP_G);
	
	//PORTD &= ~(_BV(DIR_RELAY) | _BV(ON_RELAY));
	gpio_clr_pin(RELAY_ON);
	gpio_clr_pin(RELAY_DIR);
	
	// initiera utgångar 
	//DDRD = (_BV(DIR_RELAY) | _BV(ON_RELAY));
	gpio_set_out(RELAY_ON);
	gpio_set_out(RELAY_DIR);

	// Start report timer
	Timer_SetTimeout(act_linearAct_TIMER_report, act_linearAct_ReportInterval*1000 , TimerTypeFreeRunning, 0);
#if (USE_STIMULI == 1)	
	// Set stimuli as an output
	gpio_set_out(STIMULI);
	Timer_SetTimeout(act_linearAct_TIMER_stimuli, 10, TimerTypeFreeRunning,0);
#endif
}
Beispiel #5
0
int dht_read(int pin, int* temp, int* humid) {
    // DHT sensors that come mounted on a PCB generally have
    // pull-up resistors on the data pin.  It is recommended
    // to provide an external pull-up resistor otherwise...
    int16_t t = 0;
    int16_t h = 0;
                 
    gpio_set_pullup(pin, false, false);

    if (!dht_read_data(pin, &h, &t)) return -1;
    printf("Humidity: %d%% Temp: %dC\n", h, t);
    *temp = t;
    *humid = h;
    return 0;
}
Beispiel #6
0
void notmain() {
  led_init();
  gpio_init();

  gpio_set_pullup(GPIO_PIN23);
  gpio_set_output(GPIO_PIN23);

  while (1) {
    int i;
    gpio_pin_write(GPIO_PIN23, 0);
    for (i = 0; i < 100; i++) {}
    gpio_pin_write(GPIO_PIN23, 1);
    for (i = 0; i < 100; i++) {}
  } 
}
Beispiel #7
0
void hall_effect(void) {

	const unsigned vout= GPIO_PIN4;

  	gpio_set_function(vout, GPIO_FUNC_INPUT);
  	gpio_set_pullup(vout);

	for(int i = 0; i < 10; i++) {
  		while(gpio_read(vout) == 1) {}
		printf("magnet close!\n");
  		while(gpio_read(vout) == 0) {}
		printf("magnet out of range!\n");
	}

  	//reboot();
}
Beispiel #8
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();
}
Beispiel #9
0
void dhtMeasurementTask(void *pvParameters)
{
    int16_t temperature = 0;
    int16_t humidity = 0;

    // DHT sensors that come mounted on a PCB generally have
    // pull-up resistors on the data pin.  It is recommended
    // to provide an external pull-up resistor otherwise...
    gpio_set_pullup(dht_gpio, false, false);

    while(1) {
        if (dht_read_data(dht_gpio, &humidity, &temperature)) {
            printf("Humidity: %d%% Temp: %dC\n", 
                    humidity / 10, 
                    temperature / 10);
        } else {
            printf("Could not read data from sensor\n");
        }

        // Three second delay...
        vTaskDelay(3000 / portTICK_RATE_MS);
    }
}
Beispiel #10
0
void sns_counter_Init(void)
{
#if sns_counter_USEEEPROM==1
	if (EEDATA_OK)
	{
		//Use stored data to set initial values for the module
		sns_counter_ReportInterval = eeprom_read_byte(EEDATA.reportInterval);
#ifdef sns_counter_CH0
		Count[0] = eeprom_read_dword(EEDATA32.Count[0]);
#endif
#ifdef sns_counter_CH1
		Count[1] = eeprom_read_dword(EEDATA32.Count[1]);
#endif
#ifdef sns_counter_CH2
		Count[2] = eeprom_read_dword(EEDATA32.Count[2]);
#endif
#ifdef sns_counter_CH3
		Count[3] = eeprom_read_dword(EEDATA32.Count[3]);
#endif
#ifdef sns_counter_CH4
		Count[4] = eeprom_read_dword(EEDATA32.Count[4]);
#endif
#ifdef sns_counter_CH5
		Count[5] = eeprom_read_dword(EEDATA32.Count[5]);
#endif
#ifdef sns_counter_CH6
		Count[6] = eeprom_read_dword(EEDATA32.Count[6]);
#endif
#ifdef sns_counter_CH7
		Count[7] = eeprom_read_dword(EEDATA32.Count[7]);
#endif
	} else
	{	//The CRC of the EEPROM is not correct, store default values and update CRC
		sns_counter_save_data();
	}
#endif
	//Initialize hardware etc here
#ifdef sns_counter_CH0
	#if (sns_counter_CH0_pullup == 1)
		gpio_set_pullup(sns_counter_CH0);
	#else
		gpio_clr_pullup(sns_counter_CH0);
	#endif
		gpio_set_in(sns_counter_CH0);
		Pcint_SetCallbackPin(sns_counter_PCINT_CH0, sns_counter_CH0 , &sns_counter_pcint_callback);
#endif
#ifdef sns_counter_CH1
	#if (sns_counter_CH1_pullup == 1)
		gpio_set_pullup(sns_counter_CH1);
	#else
		gpio_clr_pullup(sns_counter_CH1);
	#endif
		gpio_set_in(sns_counter_CH1);
		Pcint_SetCallbackPin(sns_counter_PCINT_CH1, sns_counter_CH1 , &sns_counter_pcint_callback);
#endif
#ifdef sns_counter_CH2
	#if (sns_counter_CH2_pullup == 1)
		gpio_set_pullup(sns_counter_CH2);
	#else
		gpio_clr_pullup(sns_counter_CH2);
	#endif
		gpio_set_in(sns_counter_CH2);
		Pcint_SetCallbackPin(sns_counter_PCINT_CH2, sns_counter_CH2 , &sns_counter_pcint_callback);
#endif
#ifdef sns_counter_CH3
	#if (sns_counter_CH3_pullup == 1)
		gpio_set_pullup(sns_counter_CH3);
	#else
		gpio_clr_pullup(sns_counter_CH3);
	#endif
		gpio_set_in(sns_counter_CH3);
		Pcint_SetCallbackPin(sns_counter_PCINT_CH3, sns_counter_CH3 , &sns_counter_pcint_callback);
#endif
#ifdef sns_counter_CH4
	#if (sns_counter_CH4_pullup == 1)
		gpio_set_pullup(sns_counter_CH4);
	#else
		gpio_clr_pullup(sns_counter_CH4);
	#endif
		gpio_set_in(sns_counter_CH4);
		Pcint_SetCallbackPin(sns_counter_PCINT_CH4, sns_counter_CH4 , &sns_counter_pcint_callback);
#endif
#ifdef sns_counter_CH5
	#if (sns_counter_CH5_pullup == 1)
		gpio_set_pullup(sns_counter_CH5);
	#else
		gpio_clr_pullup(sns_counter_CH5);
	#endif
		gpio_set_in(sns_counter_CH5);
		Pcint_SetCallbackPin(sns_counter_PCINT_CH5, sns_counter_CH5 , &sns_counter_pcint_callback);
#endif
#ifdef sns_counter_CH6
	#if (sns_counter_CH6_pullup == 1)
		gpio_set_pullup(sns_counter_CH6);
	#else
		gpio_clr_pullup(sns_counter_CH6);
	#endif
		gpio_set_in(sns_counter_CH6);
		Pcint_SetCallbackPin(sns_counter_PCINT_CH6, sns_counter_CH6 , &sns_counter_pcint_callback);
#endif
#ifdef sns_counter_CH7
	#if (sns_counter_CH7_pullup == 1)
		gpio_set_pullup(sns_counter_CH7);
	#else
		gpio_clr_pullup(sns_counter_CH7);
	#endif
		gpio_set_in(sns_counter_CH7);
		Pcint_SetCallbackPin(sns_counter_PCINT_CH7, sns_counter_CH7 , &sns_counter_pcint_callback);
#endif

#ifdef sns_counter_SEND_TIMER
	Timer_SetTimeout(sns_counter_SEND_TIMER, sns_counter_ReportInterval*1000 , TimerTypeFreeRunning, 0);
#endif
}