void wake_up_temp_sens(void) { int info; ioport_set_pin_level(TEMP_CS,0); delay_ms(1); for(int i=0;i<16;i++) { info=info|(ioport_get_pin_level(TEMP_IO)<<(15-i)); ioport_set_pin_level(TEMP_CLK,1); delay_ms(1); ioport_set_pin_level(TEMP_CLK,0); delay_ms(1); } ioport_set_pin_dir(TEMP_IO,IOPORT_DIR_OUTPUT); ioport_set_pin_level(IO,0); // sends the command 0x0000 so it can wake up for(int i=0;i<16;i++) { ioport_set_pin_level(TEMP_CLK,1); delay_ms(1); ioport_set_pin_level(TEMP_CLK,0); delay_ms(1); } ioport_set_pin_dir(TEMP_IO,IOPORT_DIR_INPUT); ioport_set_pin_level(TEMP_CS,1); }
void init_Usart (void) { ioport_set_pin_dir(PIO_PA21_IDX,IOPORT_DIR_INPUT); ioport_set_pin_dir(PIO_PB4_IDX,IOPORT_DIR_OUTPUT); const sam_usart_opt_t usart_console_settings = { USART_SERIAL_BAUDRATE, USART_SERIAL_CHAR_LENGTH, USART_SERIAL_PARITY, USART_SERIAL_STOP_BIT, US_MR_CHMODE_NORMAL }; #if SAM4L sysclk_enable_peripheral_clock(USART_SERIAL); #else sysclk_enable_peripheral_clock(USART_SERIAL_ID); #endif usart_init_rs232(USART_SERIAL, &usart_console_settings, sysclk_get_main_hz()/2); usart_enable_tx(USART_SERIAL); usart_enable_rx(USART_SERIAL); // how to enable an interrupt( use three steps ):use these functions: -usart_enable_interrupt- Then -NVIC_EnableIRQ(USART_SERIAL_IRQ);- & Then add this function void USART_SERIAL_ISR_HANDLER(void) usart_enable_interrupt(USART_SERIAL, US_IER_RXRDY); NVIC_EnableIRQ(USART_SERIAL_IRQ); }
/** * \brief Test IOPORT pin level is getting changed. * * This function set the direction of CONF_OUT_PIN to output mode with pull-up * enabled and read the status of pin using CONF_IN_PIN which is configured in * input mode. * * The pin CONF_OUT_PIN and CONF_IN_PIN are shorted using a jumper. * * \param test Current test case. */ static void run_ioport_pin_test(const struct test_case *test) { static volatile pin_mask_t pin_val; /* Set output direction on the given IO Pin */ ioport_set_pin_dir(CONF_OUT_PIN, IOPORT_DIR_OUTPUT); /* Set direction and pull-up on the given IO Pin */ ioport_set_pin_dir(CONF_IN_PIN, IOPORT_DIR_INPUT); ioport_set_pin_mode(CONF_IN_PIN, IOPORT_MODE_PULLUP); /* Set IO pin as high */ ioport_set_pin_level(CONF_OUT_PIN, IOPORT_PIN_LEVEL_HIGH); delay_ms(10); pin_val = ioport_get_pin_level(CONF_IN_PIN); test_assert_true(test, pin_val == 1, "IOPORT Set pin level high test failed"); /* Set IO pin as low */ ioport_set_pin_level(CONF_OUT_PIN, IOPORT_PIN_LEVEL_LOW); delay_ms(10); pin_val = ioport_get_pin_level(CONF_IN_PIN); test_assert_true(test, pin_val == 0, "IOPORT Set pin level low test failed"); /* Toggle IO pin */ ioport_toggle_pin_level(CONF_OUT_PIN); delay_ms(10); pin_val = ioport_get_pin_level(CONF_IN_PIN); test_assert_true(test, pin_val == 1, "IOPORT Set pin level toggle test failed"); }
int main(void) { /* Use static volatile to make it available in debug watch */ static volatile bool pin_val; sysclk_init(); board_init(); ioport_init(); delay_init(sysclk_get_cpu_hz()); /* Set output direction on the given LED IOPORTs */ ioport_set_pin_dir(EXAMPLE_LED, IOPORT_DIR_OUTPUT); /* Set direction and pullup on the given button IOPORT */ ioport_set_pin_dir(EXAMPLE_BUTTON, IOPORT_DIR_INPUT); ioport_set_pin_mode(EXAMPLE_BUTTON, IOPORT_MODE_PULLUP); /* Set LED IOPORTs high */ ioport_set_pin_level(EXAMPLE_LED, IOPORT_PIN_LEVEL_HIGH); while (true) { /* Toggle LED IOPORTs with half a second interval */ ioport_toggle_pin_level(EXAMPLE_LED); delay_ms(500); /* Get value from button port */ /* Use watch with debugger to see it */ pin_val = ioport_get_pin_level(EXAMPLE_BUTTON); } }
int main (void) { /* Insert system clock initialization code here (sysclk_init()). */ board_init(); sysclk_init(); delay_init(sysclk_get_cpu_hz()); //gpio_configure_pin(PORTA5,1); ioport_init(); ioport_set_pin_dir(LED_GREEN,IOPORT_DIR_OUTPUT); ioport_set_pin_dir(LED_RED,IOPORT_DIR_OUTPUT); /* Insert application code here, after the board has been initialized. */ ioport_set_pin_high(LED_RED); ioport_set_pin_low(LED_GREEN); //gpio_set_pin_high(PORTA5); while(true){ ioport_toggle_pin(LED_GREEN); ioport_toggle_pin(LED_RED); delay_ms(500); } }
int main(void) { // prepare the i/o for LEDs ioport_init(); ioport_set_pin_dir(RED, IOPORT_DIR_OUTPUT); ioport_set_pin_dir(YELLOW, IOPORT_DIR_OUTPUT); // clock init & enable system clock to all peripheral modules sysclk_init(); sysclk_enable_module(SYSCLK_PORT_GEN, 0xff); sysclk_enable_module(SYSCLK_PORT_A, 0xff); sysclk_enable_module(SYSCLK_PORT_B, 0xff); sysclk_enable_module(SYSCLK_PORT_C, 0xff); sysclk_enable_module(SYSCLK_PORT_D, 0xff); sysclk_enable_module(SYSCLK_PORT_E, 0xff); sysclk_enable_module(SYSCLK_PORT_F, 0xff); // start tasks xTaskCreate(blink1, (signed char*) "blink1", 1024, NULL, 2, NULL); xTaskCreate(blink2, (signed char*) "blink2", 1024, NULL, 2, NULL); xTaskCreate(uartLoopBack, (signed char*) "uart1", 1024, NULL, 2, NULL); xTaskCreate(twi_example, (signed char*) "twi", 1024, NULL, 2, NULL); vTaskStartScheduler(); return 0; }
void shutdown_temp_sens(void) { int info; ioport_set_pin_level(TEMP_CS,0); delay_ms(1); for(int i=0;i<16;i++) { info=info|(ioport_get_pin_level(TEMP_IO)<<(15-i)); ioport_set_pin_level(TEMP_CLK,1); delay_ms(1); ioport_set_pin_level(TEMP_CLK,0); delay_ms(1); } ioport_set_pin_dir(TEMP_IO,IOPORT_DIR_OUTPUT); ioport_set_pin_level(IO,1); // sends the command 0xFFFF so it can enter the shutdown mode for(int i=0;i<16;i++) { ioport_set_pin_level(TEMP_CLK,1); delay_ms(1); ioport_set_pin_level(TEMP_CLK,0); delay_ms(1); } ioport_set_pin_dir(TEMP_IO,IOPORT_DIR_INPUT); ioport_set_pin_level(TEMP_CS,1); }
void leds_init(void) { ioport_set_pin_dir(LED1, IOPORT_DIR_OUTPUT); ioport_set_pin_dir(LED2, IOPORT_DIR_OUTPUT); ioport_set_pin_dir(LED3, IOPORT_DIR_OUTPUT); ioport_set_pin_dir(LED4, IOPORT_DIR_OUTPUT); }
void init_temp_sens() { ioport_set_pin_dir(TEMP_CLK, IOPORT_DIR_OUTPUT); ioport_set_pin_dir(TEMP_CS, IOPORT_DIR_OUTPUT); ioport_set_pin_dir(TEMP_IO, IOPORT_DIR_INPUT); ioport_set_pin_level(TEMP_CS,1); ioport_set_pin_level(TEMP_CLK,0); }
void capsense_init(void) { ioport_set_pin_dir(SENS_PIN, IOPORT_DIR_INPUT); ioport_set_pin_dir(TOUCH_TX_PIN, IOPORT_DIR_OUTPUT); PORTA.DIRCLR = 0xFF; //all in PORTA.PIN3CTRL = PORT_OPC_TOTEM_gc; }
int lcdInit(void) /* Initializes the display on the LCD shield, returns 1 if everything is ok */ { int all_ok=1; /* at the beginning assume nothing works */ /* At power on */ ioport_set_pin_dir(LCD_RS, IOPORT_DIR_OUTPUT); ioport_set_pin_dir(LCD_Enable, IOPORT_DIR_OUTPUT); ioport_set_port_dir(IOPORT_PIOC, LCD_mask_D4_D7, IOPORT_DIR_OUTPUT); ioport_set_pin_level(LCD_Enable, LOW); delayMicroseconds(30000); /* wait > 15 ms */ ioport_set_pin_level(LCD_RS, LOW); /* Function set (interface is 8 bit long) */ ioport_set_pin_level(LCD_D4, HIGH); ioport_set_pin_level(LCD_D5, HIGH); ioport_set_pin_level(LCD_D6, LOW); ioport_set_pin_level(LCD_D7, LOW); ioport_set_pin_level(LCD_Enable, HIGH); delayMicroseconds(1); /* wait 1 us */ ioport_set_pin_level(LCD_Enable, LOW); delayMicroseconds(4100); /* wait for more than 4,1 ms */ ioport_set_pin_level(LCD_D4, HIGH); ioport_set_pin_level(LCD_D5, HIGH); ioport_set_pin_level(LCD_D6, LOW); ioport_set_pin_level(LCD_D7, LOW); ioport_set_pin_level(LCD_Enable, HIGH); delayMicroseconds(1); /* delay 1 us */ ioport_set_pin_level(LCD_Enable, LOW); delayMicroseconds(100); /* wait 100 us */ ioport_set_pin_level(LCD_D4, HIGH); ioport_set_pin_level(LCD_D5, HIGH); ioport_set_pin_level(LCD_D6, LOW); ioport_set_pin_level(LCD_D7, LOW); ioport_set_pin_level(LCD_Enable, HIGH); delayMicroseconds(1); /* wait 1 us */ ioport_set_pin_level(LCD_Enable, LOW); delayMicroseconds(100); /* wait 100 us */ /* Set display to 4-bit input */ ioport_set_pin_level(LCD_D4, LOW); ioport_set_pin_level(LCD_D5, HIGH); ioport_set_pin_level(LCD_D6, LOW); ioport_set_pin_level(LCD_D7, LOW); ioport_set_pin_level(LCD_Enable, HIGH); delayMicroseconds(1); ioport_set_pin_level(LCD_Enable, LOW); delayMicroseconds(100); lcdWrite(0b00101000, LOW); /* Two rows, small font */ lcdWrite(0b00001000, LOW); /* Display off */ lcdWrite(0b00000001, LOW); /* Display clear */ delayMicroseconds(3000); lcdWrite(0b00000110, LOW); /* Entry mode set: move cursor right, no display shift */ lcdWrite(0b00001111 ,LOW); /* Display on, cursor on, blinking on */ all_ok = 0; /* simple return statement showing that the initialization of the LCD has completed */ return all_ok; }
/* Funktionen initierar PWM-signalen */ void pwm_setup(void) { pmc_enable_periph_clk(ID_PWM); pwm_channel_disable(PWM, PWM_CHANNEL); pwm_clock_t clock_setting = { .ul_clka = PWM_FREQUENCY * PWM_PERIOD, .ul_clkb = 0, .ul_mck = SYS_CLOCK }; pwm_init(PWM, &clock_setting); pwm_channel_instance.alignment = PWM_ALIGN_LEFT; pwm_channel_instance.polarity = PWM_LOW; pwm_channel_instance.ul_prescaler = PWM_CMR_CPRE_CLKA; pwm_channel_instance.ul_period = PWM_PERIOD; pwm_channel_instance.ul_duty = PWM_INIT_DUTY_CYCLE; pwm_channel_instance.channel = PWM_CHANNEL; pwm_channel_init(PWM, &pwm_channel_instance); pio_set_peripheral(PWM_PIO, PWM_PERIPHERAL, PWM_PIN); pwm_channel_enable(PWM, PWM_CHANNEL); } /* Funktionen uppdaterar PWM-signalens duty-cycle */ void update_pwm(int ul_duty) { // Kontrollerar så att angiven duty-cycle befinner sig inom rätt område (0-1000). if(ul_duty < PWM_MIN_DUTY_CYCLE) { pwm_channel_update_duty(PWM, &pwm_channel_instance, PWM_MIN_DUTY_CYCLE); } else if(ul_duty > PWM_MAX_DUTY_CYCLE) { pwm_channel_update_duty(PWM, &pwm_channel_instance, PWM_MAX_DUTY_CYCLE); } else { pwm_channel_update_duty(PWM, &pwm_channel_instance, ul_duty); } } /* Funktionen initierar motor-shielden */ void motor_shield_setup(void) { ioport_set_pin_dir(PIO_PD8_IDX, IOPORT_DIR_OUTPUT); ioport_set_pin_level(PIO_PD8_IDX, IOPORT_PIN_LEVEL_HIGH); ioport_set_pin_dir(PIO_PC21_IDX, IOPORT_DIR_OUTPUT); ioport_set_pin_level(PIO_PC21_IDX, IOPORT_PIN_LEVEL_LOW); }
static void setup_leds(void) { ioport_set_pin_mode(PIO_PC23_IDX,IOPORT_MODE_MUX_BIT0); // Pin D7 ioport_set_pin_dir(PIO_PC23_IDX,IOPORT_DIR_OUTPUT); ioport_set_pin_mode(PIO_PC24_IDX,IOPORT_MODE_MUX_BIT0); // Pin D6 ioport_set_pin_dir(PIO_PC24_IDX,IOPORT_DIR_OUTPUT); ioport_set_pin_mode(PIO_PC25_IDX,IOPORT_MODE_MUX_BIT0); // Pin D5 ioport_set_pin_dir(PIO_PC25_IDX,IOPORT_DIR_OUTPUT); }
bool init_led_pins(void) { ioport_set_pin_dir(BLU_LED, IOPORT_DIR_INPUT); ioport_set_pin_mode(BLU_LED, IOPORT_MODE_PULLDOWN); ioport_set_pin_dir(RED_LED, IOPORT_DIR_INPUT); ioport_set_pin_mode(RED_LED, IOPORT_MODE_PULLDOWN); ioport_set_pin_dir(GRE_LED, IOPORT_DIR_INPUT); ioport_set_pin_mode(GRE_LED, IOPORT_MODE_PULLDOWN); ioport_set_pin_dir(YEL_LED, IOPORT_DIR_INPUT); ioport_set_pin_mode(YEL_LED, IOPORT_MODE_PULLDOWN); return true; }
// setup the board instead of board_init() as recommended by ASF.. because christmas lights, that's why. void init (void) { static usart_serial_options_t usart_options = { .baudrate = USART_SERIAL_BAUDRATE, .charlength = USART_SERIAL_CHAR_LENGTH, .paritytype = USART_SERIAL_PARITY, .stopbits = USART_SERIAL_STOP_BIT }; // initialize ASF stuff board_init(); sysclk_init(); ioport_init(); pmic_init(); pmic_set_scheduling(PMIC_SCH_FIXED_PRIORITY); // remap, enable TX, and configure USART on PORT C PORTC.REMAP |= PR_USART0_bm; PORTC.DIR |= (1 << PIN7_bp); sysclk_enable_module(SYSCLK_PORT_C, PR_USART0_bm); usart_init_rs232(USART_SERIAL, &usart_options); // setup timer for PWM tc45_enable(&TCC4); tc45_set_overflow_interrupt_callback(&TCC4, pwm_callback); tc45_set_wgm(&TCC4, TC45_WG_NORMAL); tc45_write_period(&TCC4, 256); tc45_set_overflow_interrupt_level(&TCC4, TC45_INT_LVL_MED); // enable all channels and turn off (high) ioport_set_port_dir(IOPORT_PORTA, PORTA_MASK, IOPORT_DIR_OUTPUT); ioport_set_port_dir(IOPORT_PORTD, PORTD_MASK, IOPORT_DIR_OUTPUT); ioport_set_port_dir(IOPORT_PORTR, PORTR_MASK, IOPORT_DIR_OUTPUT); ioport_set_port_level(IOPORT_PORTA, PORTA_MASK, 0xFF); ioport_set_port_level(IOPORT_PORTD, PORTD_MASK, 0xFF); ioport_set_port_level(IOPORT_PORTR, PORTR_MASK, 0xFF); for (uint8_t i=0; i<NUM_CHANNELS; i++) { compare[i] = 0; compbuff[i] = 0; } // enable status LEDs and turn off ioport_set_pin_dir(LED_STATUS, IOPORT_DIR_OUTPUT); ioport_set_pin_dir(LED_DATA, IOPORT_DIR_OUTPUT); ioport_set_pin_level(LED_STATUS, 1); ioport_set_pin_level(LED_DATA, 1); // enable interrupts and start timer for PWM cpu_irq_enable(); tc45_write_clock_source(&TCC4, TC45_CLKSEL_DIV2_gc); }
void drive_DQ_low_and_release_the_bus(unsigned char idx) { unsigned char ioPin; int32_t ioFlagsOutput, ioFlagsInput; ioPin = io_pin(idx); ioport_set_pin_dir(ioPin, IOPORT_DIR_OUTPUT); ioport_set_pin_level(ioPin, IOPORT_PIN_LEVEL_LOW); udelay(A); //tW1L 5-15us ioport_set_pin_dir(ioPin, IOPORT_DIR_INPUT); }
int main (void) { U8 msg[32] = "Hi ArduSub\n\r"; pmic_init(); sysclk_init(); adc_init(); thruster_init(); ioport_init(); timer_init(10000); timer_set_counts(TIMER_HEARTBEAT,timer_ms_to_counts(250)); timer_start(TIMER_HEARTBEAT); cpu_irq_enable(); volatile U8 count = 0; ioport_set_pin_dir(LED1,IOPORT_DIR_OUTPUT); ioport_set_pin_dir(LED2,IOPORT_DIR_OUTPUT); ioport_set_pin_dir(UARTD_TX,IOPORT_DIR_OUTPUT); ioport_set_pin_dir(UARTD_RX,IOPORT_DIR_INPUT); ioport_set_pin_dir(TXEN,IOPORT_DIR_OUTPUT); board_init(); uart_init(19200); do { message_tasks(); count++; if (count > 52) { count = 0; } if(timer_is_expired(TIMER_HEARTBEAT)) { timer_reset(TIMER_HEARTBEAT); board_pres_read(); ext_temp_read(); //ioport_set_pin_level(TXEN,1); //uart_write(&msg[0],12); //while(uart_tx_count() != 0); //blink heart beat LED ioport_set_pin_level(LED2,!ioport_get_pin_level(LED2)); } } while (1); // Insert application code here, after the board has been initialized. }
void board_init(void) { // Initialize IOPORTs ioport_init(); // Put all pins to default state (input & pull-up) uint32_t pin; for (pin = PIN_PA00; pin <= PIN_PC31; pin ++) { ioport_set_pin_dir(pin, IOPORT_DIR_INPUT); ioport_set_pin_mode(pin, IOPORT_MODE_PULLUP); } #if defined (CONF_BOARD_COM_PORT) ioport_set_pin_peripheral_mode(COM_PORT_RX_PIN, COM_PORT_RX_MUX); ioport_set_pin_peripheral_mode(COM_PORT_TX_PIN, COM_PORT_TX_MUX); #endif #ifdef CONF_BOARD_GLOC_LUT0_PORT ioport_set_pin_peripheral_mode(PIN_PA20D_GLOC_IN0, MUX_PA20D_GLOC_IN0); ioport_set_pin_peripheral_mode(PIN_PA21D_GLOC_IN1, MUX_PA21D_GLOC_IN1); ioport_set_pin_peripheral_mode(PIN_PA22D_GLOC_IN2, MUX_PA22D_GLOC_IN2); ioport_set_pin_peripheral_mode(PIN_PA07D_GLOC_IN3, MUX_PA07D_GLOC_IN3); ioport_set_pin_peripheral_mode(PIN_PA24D_GLOC_OUT0, MUX_PA24D_GLOC_OUT0); #endif }
OSStatus mico_gpio_initialize( mico_gpio_t gpio, mico_gpio_config_t configuration ) { ioport_mode_t mode = 0; ioport_pin_t pin = 0; enum ioport_direction dir; if(gpio == (mico_gpio_t)MICO_GPIO_UNUSED ) return kUnsupportedErr; mico_mcu_power_save_config(false); dir = ( (configuration == INPUT_PULL_UP ) || (configuration == INPUT_PULL_DOWN ) || (configuration == INPUT_HIGH_IMPEDANCE ) ) ? IOPORT_DIR_INPUT: IOPORT_DIR_OUTPUT; if ( (configuration == INPUT_PULL_UP ) || (configuration == OUTPUT_OPEN_DRAIN_PULL_UP ) ) { mode |= IOPORT_MODE_PULLUP; } else if (configuration == INPUT_PULL_DOWN ) { mode |= IOPORT_MODE_PULLDOWN; } else if ( (configuration == OUTPUT_OPEN_DRAIN_PULL_UP ) || (configuration == OUTPUT_OPEN_DRAIN_NO_PULL) ) { mode |= IOPORT_MODE_OPEN_DRAIN; } // other input debounce ,glitch filter; pin = CREATE_IOPORT_PIN(gpio_mapping[gpio].bank, gpio_mapping[gpio].number); ioport_set_pin_dir(pin, dir); ioport_set_pin_mode(pin, mode); mico_mcu_power_save_config(true); return kNoErr; }
int I2C_init( void ) { twi_options_t opt; twi_slave_fct_t twi_slave_fct; int status; double total = 0; // Initialize and enable interrupt irq_initialize_vectors(); cpu_irq_enable(); // TWI gpio pins configuration gpio_enable_module(TWI_GPIO_MAP, sizeof(TWI_GPIO_MAP) / sizeof(TWI_GPIO_MAP[0])); // initialize the interrupt flag for alerting the Pi of new data (TWI = Three Wire Interface for us) ioport_enable_pin(I2C_FLAG); ioport_set_pin_dir(I2C_FLAG,IOPORT_DIR_OUTPUT); ioport_set_pin_level(I2C_FLAG,false); // options settings opt.pba_hz = FOSC0; opt.speed = TWI_SPEED; opt.chip = EEPROM_ADDRESS; // initialize TWI driver with options twi_slave_fct.rx = &twi_slave_rx; twi_slave_fct.tx = &twi_slave_tx; twi_slave_fct.stop = &twi_slave_stop; status = twi_slave_init(&AVR32_TWI, &opt, &twi_slave_fct ); return (&s_memory[0] ); }
/** * \brief Initialize ADC and DAC used to simulate a temperature sensor * * DACB is used by the simulation plant to output a temperature reading of the * oven plate. It is set up to output a voltage on pin B2 which is marked as * ADC2 on header J2. * * ADCA is used in the control step and graphical interface to show the current * temperature of the oven plate. It is set up to read a voltage on pin A4 which * is marked as ADC4 on header J2. * * ADC2 and ADC4 should be connected together, so that the ADC samples the DAC * directly. */ void main_init_adc_dac(void) { struct adc_config adc_conf; struct adc_channel_config adcch_conf; struct dac_config dac_conf; /* Set up the DAC for the simulation to output "real" temperature */ dac_read_configuration(&DACB, &dac_conf); dac_set_conversion_parameters(&dac_conf, DAC_REF_BANDGAP, DAC_ADJ_RIGHT); dac_set_active_channel(&dac_conf, DAC_CH0, 0); dac_write_configuration(&DACB, &dac_conf); dac_enable(&DACB); /* Set up the ADC for the controller to read "real" temperature */ adc_read_configuration(&ADCA, &adc_conf); adcch_read_configuration(&ADCA, ADC_CH0, &adcch_conf); adc_set_conversion_parameters(&adc_conf, ADC_SIGN_ON, ADC_RES_12, ADC_REF_BANDGAP); adc_set_clock_rate(&adc_conf, 20000UL); adc_set_conversion_trigger(&adc_conf, ADC_TRIG_MANUAL, 1, 0); adc_write_configuration(&ADCA, &adc_conf); adcch_set_input(&adcch_conf, ADCCH_POS_PIN4, ADCCH_NEG_NONE, 1); adcch_write_configuration(&ADCA, ADC_CH0, &adcch_conf); adc_enable(&ADCA); adc_start_conversion(&ADCA, ADC_CH0); /* Enable pull-down, so an open circuit can be detected */ ioport_set_pin_dir(J2_PIN4, IOPORT_DIR_INPUT); ioport_set_pin_mode(J2_PIN4, IOPORT_MODE_PULLDOWN); }
void bluetooth_init(void) { ioport_set_pin_dir(BT_TX,IOPORT_DIR_OUTPUT); static usart_serial_options_t usart_options = { .baudrate = 115200, .charlength = USART_CHSIZE_8BIT_gc, .paritytype = USART_PMODE_DISABLED_gc, .stopbits = false }; usart_serial_init(BLUETOOTH, &usart_options); #ifdef PRINTF_BLUETOOTH // setup our stdio stream stdout = &mystdout; stdin = &mystdout; #endif } void bluetooth_init_interrupt(void) { pmic_init(); pmic_set_scheduling(PMIC_SCH_ROUND_ROBIN); USARTD0.CTRLA = USART_RXCINTLVL_HI_gc; cpu_irq_enable(); }
static void initGpio(void) { ioport_init(); // PIOB ioport_set_pin_level(LED0_GPIO, false); ioport_set_pin_dir(LED0_GPIO, IOPORT_DIR_OUTPUT); }
void board_init(void) { /* This function is meant to contain board-specific initialization code * for, e.g., the I/O pins. The initialization can rely on application- * specific board configuration, found in conf_board.h. */ ioport_init(); #ifdef BOARD_REV_A // USART PORTD_REMAP = USARTD_REMAP; PORTD_DIRSET = PIN7_bm; //LEDs ioport_set_pin_dir(LED_GREEN, IOPORT_DIR_OUTPUT); ioport_set_pin_dir(LED_RED, IOPORT_DIR_OUTPUT); #endif #ifdef BOARD_REV_B // USART PORTD_REMAP = USARTD_REMAP; PORTD_DIRSET = PIN7_bm; //Button ioport_set_pin_dir(BUT_1, IOPORT_DIR_INPUT); //LEDs ioport_set_pin_dir(LED_GREEN, IOPORT_DIR_OUTPUT); ioport_set_pin_dir(LED_RED, IOPORT_DIR_OUTPUT); #endif #ifdef ENABLE_USART // startup USART static usart_rs232_options_t usart_serial_options = { .baudrate = USART_SERIAL_BAUDRATE, .charlength = USART_SERIAL_CHAR_LENGTH, .paritytype = USART_SERIAL_PARITY, .stopbits = USART_SERIAL_STOP_BIT }; sysclk_enable_module(SYSCLK_PORT_D, PR_USART0_bm); //usart_init_rs232(USART_SERIAL, &usart_serial_options); stdio_serial_init(USART_SERIAL, &usart_serial_options); #endif }
void HM10ReadDebugByte (volatile uint8_t * byte1, volatile uint8_t * byte2) { unsigned char data = 0; ioport_set_pin_dir(HM_10_DD, IOPORT_DIR_INPUT); timer_delay (HM_10_CLOCK_DATA); while (ioport_get_pin_level(HM_10_DD) == true) // CC2540 is not ready to send, sample 8 bits and trash { for (unsigned char bit = 0; bit < 8; bit++) { HM_10_DC_UP(); timer_delay (HM_10_CLOCK_DATA); HM_10_DC_DOWN(); timer_delay (HM_10_CLOCK_DATA); } } data = 0; for (unsigned char bit = 0; bit < 8; bit++) { HM_10_DC_UP(); timer_delay (HM_10_CLOCK_DATA); HM_10_DC_DOWN(); data |= ioport_get_pin_level(HM_10_DD); if (bit < 7) data <<= 1; timer_delay (HM_10_CLOCK_DATA); } if (byte1 != NULL) *byte1 = data; if (byte2 != NULL) { data = 0; for (unsigned char bit = 0; bit < 8; bit++) { HM_10_DC_UP(); timer_delay (HM_10_CLOCK_DATA); HM_10_DC_DOWN(); data |= ioport_get_pin_level(HM_10_DD); if (bit < 7) data <<= 1; timer_delay (HM_10_CLOCK_DATA); } *byte2 = data; } ioport_set_pin_dir(HM_10_DD, IOPORT_DIR_OUTPUT); timer_delay (HM_10_CLOCK_DATA); }
void board_init(void) { #ifdef KEY_RC_BOARD /* On board Button initialization */ ioport_configure_pin(BUTTON_IRQ_PIN_1,IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(BUTTON_IRQ_PIN_2,IOPORT_DIR_INPUT | IOPORT_PULL_UP); ioport_configure_pin(BUTTON_IRQ_PIN_3,IOPORT_DIR_INPUT | IOPORT_PULL_UP); set_button_pins_for_normal_mode(); /* Initialize the IRQ lines' interrupt behaviour. */ DISABLE_ALL_BUTTON_IRQS(); /* LED Init */ /* LCD initialization for inactive use */ /* On board LED initialization */ ioport_configure_pin(LCD_CS_ON_BOARD, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_set_port_dir(IOPORT_PORTE,KEY_RC_IO_MASK,IOPORT_DIR_OUTPUT); ioport_set_port_level(IOPORT_PORTE,KEY_RC_IO_MASK,KEY_RC_IO_MASK); ioport_set_pin_dir(IOPORT_CREATE_PIN(PORTG , 2),IOPORT_DIR_INPUT); ioport_set_pin_mode(IOPORT_CREATE_PIN(PORTG , 2), IOPORT_MODE_PULLUP); LATCH_INIT(); /* Init ADC for the Accelerometer */ adc_init(); // LATCH_INIT(); /* Enable Accelerometer by enabling the PWR pin in the Latch */ acc_init(); update_latch_status(); /* Apply latch pulse to set LED status */ pulse_latch(); #else /* To identify if it is a plain or STB*/ board_identify(); /* On board LED initialization */ ioport_configure_pin(LED0_RCB,IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED1_RCB,IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); ioport_configure_pin(LED2_RCB,IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH); /* On board Switch initialization */ ioport_configure_pin(GPIO_PUSH_BUTTON_0,IOPORT_DIR_INPUT | IOPORT_PULL_UP); #ifdef BREAKOUT_BOARD //Enable RCB_BB RS232 level converter ioport_set_port_dir(IOPORT_PORTD,BB_SIO_MASK,IOPORT_DIR_OUTPUT); ioport_set_port_level(IOPORT_PORTD,BB_SIO_MASK,BB_SIO_VAL); #endif #endif }
void init_gpio_pins(void) { ioport_enable_pin(LED_1); ioport_enable_pin(LED_2); ioport_enable_pin(LED_3); ioport_enable_pin(HM_10_RESET); ioport_enable_pin(HM_10_DD); ioport_enable_pin(HM_10_DC); ioport_enable_pin(HM_10_MSG); ioport_set_pin_dir(LED_1, IOPORT_DIR_OUTPUT); ioport_set_pin_dir(LED_2, IOPORT_DIR_OUTPUT); ioport_set_pin_dir(LED_3, IOPORT_DIR_OUTPUT); ioport_set_pin_dir(HM_10_RESET, IOPORT_DIR_INPUT); ioport_set_pin_dir(HM_10_DD, IOPORT_DIR_INPUT); ioport_set_pin_dir(HM_10_DC, IOPORT_DIR_INPUT); ioport_set_pin_dir(HM_10_MSG, IOPORT_DIR_INPUT); ioport_set_pin_level(LED_1, false); ioport_set_pin_level(LED_2, false); ioport_set_pin_level(LED_3, false); // LED's on /*ioport_set_pin_level(HM_10_DD, false); // DC,DD low ioport_set_pin_level(HM_10_DC, false); ioport_set_pin_level(HM_10_RESET, false); // HM-10 in reset (reset low)*/ }
// Supporting function implementation Accelerometer::Accelerometer() { // Initialize variables uint8_t value; // Configure VDDIO, SDA and SCL pins ioport_set_pin_dir(ACCELEROMETER_VDDIO_PIN, IOPORT_DIR_OUTPUT); ioport_set_pin_level(ACCELEROMETER_VDDIO_PIN, IOPORT_PIN_LEVEL_HIGH); ioport_set_pin_mode(ACCELEROMETER_SDA_PIN, IOPORT_MODE_WIREDANDPULL); ioport_set_pin_mode(ACCELEROMETER_SCL_PIN, IOPORT_MODE_WIREDANDPULL); // Configure interface twi_options_t options; options.speed = BUS_SPEED; options.chip = MASTER_ADDRESS; options.speed_reg = TWI_BAUD(sysclk_get_cpu_hz(), BUS_SPEED); // Initialize interface sysclk_enable_peripheral_clock(&TWI_MASTER); twi_master_init(&TWI_MASTER, &options); twi_master_enable(&TWI_MASTER); // Create packet twi_package_t packet; packet.addr[0] = WHO_AM_I; packet.addr_length = 1; packet.chip = ACCELEROMETER_ADDRESS; packet.buffer = &value; packet.length = 1; packet.no_wait = false; // Check if transmitting or receiving failed if(twi_master_read(&TWI_MASTER, &packet) != TWI_SUCCESS || value != DEVICE_ID) // Clear is working isWorking = false; // Otherwise else { // Reset the accelerometer writeValue(CTRL_REG2, CTRL_REG2_RST); // Wait enough time for accelerometer to initialize delay_ms(1); // Initialize settings initializeSettings(); // Calibrate //calibrate(); // Set is working isWorking = true; } }
void SX1276Reset( void ) { ioport_set_pin_dir(SX1276_RESET_PIN,IOPORT_DIR_INPUT); vTaskDelay(10/portTICK_RATE_MS); ioport_set_pin_dir(SX1276_RESET_PIN,IOPORT_DIR_OUTPUT); ioport_set_pin_level(SX1276_RESET_PIN, false); vTaskDelay(10/portTICK_RATE_MS); ioport_set_pin_dir(SX1276_RESET_PIN,IOPORT_DIR_INPUT); vTaskDelay(10/portTICK_RATE_MS); }
int main(void) { sysclk_init(); board_init(); ioport_init(); /* Set output direction on the given LED IOPORTs */ ioport_set_pin_dir(EXAMPLE_LED, IOPORT_DIR_OUTPUT); /* Set direction and pullup on the given button IOPORT */ ioport_set_pin_dir(EXAMPLE_BUTTON, IOPORT_DIR_INPUT); ioport_set_pin_mode(EXAMPLE_BUTTON, IOPORT_MODE_PULLUP); while (true) { /* Get value from button and output it on led */ ioport_set_pin_level(EXAMPLE_LED, ioport_get_pin_level(EXAMPLE_BUTTON)); } }