/** @brief Function for configuring pins 0-7 as inputs and 8-15 as outputs. * */ static void init(void) { // Port0 (0-7 as inputs) nrf_gpio_range_cfg_input(BUTTON_START, BUTTON_STOP, BUTTON_PULL); // Port1 (8-15 as outputs) nrf_gpio_range_cfg_output(LED_START, LED_STOP); }
/** Configure pins 0-7 as inputs and 8-15 as outputs. * */ static void init(void) { // Port0 (0-7 as inputs) nrf_gpio_range_cfg_input(0, 7, NRF_GPIO_PIN_NOPULL); // Port1 (8-15 as outputs) nrf_gpio_range_cfg_output(8, 15); }
/** * @brief Function for application main entry. */ int main(void) { // Start 16 MHz crystal oscillator. NRF_CLOCK->EVENTS_HFCLKSTARTED = 0; NRF_CLOCK->TASKS_HFCLKSTART = 1; // Wait for the external oscillator to start up. while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) { // Do nothing. } // Set Port 0 as input. nrf_gpio_range_cfg_input(BUTTON_START, BUTTON_STOP, BUTTON_PULL); // Set Port 1 as output. nrf_gpio_range_cfg_output(LED_START, LED_STOP); // Set radio configuration parameters. radio_configure(); // Set payload pointer. NRF_RADIO->PACKETPTR = (uint32_t)packet; while (true) { // Read Data to send, button signals are default high, and low when pressed. packet[0] = ~(nrf_gpio_port_read(NRF_GPIO_PORT_SELECT_PORT0)); // Write GPIO to payload byte 0. NRF_RADIO->EVENTS_READY = 0U; NRF_RADIO->TASKS_TXEN = 1; // Enable radio and wait for ready. while (NRF_RADIO->EVENTS_READY == 0U) { // Do nothing. } // Start transmission. NRF_RADIO->TASKS_START = 1U; NRF_RADIO->EVENTS_END = 0U; while (NRF_RADIO->EVENTS_END == 0U) // Wait for end of the transmission packet. { // Do nothing. } // Write sent data to port 1. nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT1, packet[0]); NRF_RADIO->EVENTS_DISABLED = 0U; NRF_RADIO->TASKS_DISABLE = 1U; // Disable the radio. while (NRF_RADIO->EVENTS_DISABLED == 0U) { // Do nothing. } } }
/*====================================================================================================*/ void NRF51_GPIO_Config( void ) { nrf_gpio_range_cfg_output(LED_1, LED_4); nrf_gpio_range_cfg_input(KEY_1, KEY_4, NRF_GPIO_PIN_PULLUP); LED1_Set(); LED2_Set(); LED3_Set(); LED4_Set(); }
/** @brief Function for initializing the GPIO Tasks/Events peripheral. */ static void gpiote_init(void) { // Connect GPIO input buffers and configure PWM_OUTPUT_PIN_NUMBER as an output. nrf_gpio_range_cfg_input(BUTTON_START, BUTTON_STOP, BUTTON_PULL); nrf_gpio_cfg_output(PWM_OUTPUT_PIN_NUMBER); nrf_gpio_port_clear(NRF_GPIO_PORT_SELECT_PORT0, 0xFF); // Configure GPIOTE channel 0 to toggle the PWM pin state // @note Only one GPIOTE task can be connected to an output pin. nrf_gpiote_task_config(0, PWM_OUTPUT_PIN_NUMBER, \ NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW); }
/** * @brief Function for application main entry. * @return 0. int return type required by ANSI/ISO standard. */ int main(void) { const uint8_t *key_packet; uint8_t key_packet_size; #ifdef USE_UART simple_uart_config(0, SIMPLE_UART_TXD_PIN_NUMBER, 0, SIMPLE_UART_RXD_PIN_NUMBER, false); // Hardware flow control not used in this example. #else // Configure pins 24-30 for LEDs. Note that pin 31 is not connected. nrf_gpio_range_cfg_output(24, 30); #endif // Enable pulldowns on row port, see matrix_row_port. nrf_gpio_range_cfg_input(16, 23, NRF_GPIO_PIN_PULLDOWN); // Column pin configuration, see matrix_column_port. nrf_gpio_range_cfg_output(0, 15); if (cherry8x16_init(matrix_row_port, matrix_column_port, CHERRY8x16_DEFAULT_KEY_LOOKUP_MATRIX) != CHERRY8x16_OK) { #ifdef USE_UART simple_uart_putstring((const uint8_t *)"Init failed."); #else nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT3, 0x55); #endif while (true) { // Do nothing. } } while(true) { if (cherry8x16_new_packet(&key_packet, &key_packet_size)) { #ifdef USE_UART // Send the whole key packet over UART. uart_puthidstring((char*)&key_packet[KEY_PACKET_KEY_INDEX]); #else // Show modifier key state using the LEDs. Note LED's use GPIO pins from 8 to 15. nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT3, key_packet[KEY_PACKET_MODIFIER_KEY_INDEX]); #endif } nrf_delay_ms(25); } }
void init(void) { /* Start 16 MHz crystal oscillator */ NRF_CLOCK->EVENTS_HFCLKSTARTED = 0; NRF_CLOCK->TASKS_HFCLKSTART = 1; /* Wait for the external oscillator to start up */ while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) { } // Set radio configuration parameters radio_configure(); // Set payload pointer NRF_RADIO->PACKETPTR = (uint32_t)packet; nrf_gpio_range_cfg_input(BUTTON_START, BUTTON_STOP, NRF_GPIO_PIN_PULLUP); }
/*====================================================================================================*/ void GPIO_Config( void ) { nrf_gpio_range_cfg_output(LED_1, LED_4); nrf_gpio_range_cfg_input(KEY_1, KEY_4, NRF_GPIO_PIN_PULLUP); }