int main() { uint8_t output_state = 0; nrf_gpio_pin_dir_set(LED_PIN, NRF_GPIO_PIN_DIR_OUTPUT); int n = 0; initialise_monitor_handles(); printf("hello world!\n"); while(++n) { printf("round %d\n", n); nrf_delay_ms(1000); if (output_state == 1) nrf_gpio_pin_set(LED_PIN); else nrf_gpio_pin_clear(LED_PIN); output_state = (output_state + 1) & 1; nrf_delay_ms(100); } return 0; }
void setup_led_pins() { nrf_gpio_pin_dir_set(PIN_LED_RED_BRIGHT, NRF_GPIO_PIN_DIR_OUTPUT); nrf_gpio_pin_dir_set(PIN_LED_GREEN, NRF_GPIO_PIN_DIR_OUTPUT); nrf_gpio_pin_dir_set(PIN_LED_YELLOW_1, NRF_GPIO_PIN_DIR_OUTPUT); nrf_gpio_pin_dir_set(PIN_LED_WHITE_1, NRF_GPIO_PIN_DIR_OUTPUT); nrf_gpio_pin_dir_set(PIN_LED_YELLOW_2, NRF_GPIO_PIN_DIR_OUTPUT); nrf_gpio_pin_dir_set(PIN_LED_BLUE, NRF_GPIO_PIN_DIR_OUTPUT); nrf_gpio_pin_dir_set(PIN_LED_RED, NRF_GPIO_PIN_DIR_OUTPUT); nrf_gpio_pin_dir_set(PIN_LED_WHITE_2, NRF_GPIO_PIN_DIR_OUTPUT); }
void uart_setup() { uart_disable; // configure transmission nrf_gpio_pin_dir_set(PIN_UART_TXD, NRF_GPIO_PIN_DIR_OUTPUT); uart_select_pin_as_TXD(PIN_UART_TXD); uart_select_pin_as_RTS(UART_PIN_DISABLE); uart_select_pin_as_CTS(UART_PIN_DISABLE); uart_set_baud(baud_9600); uart_set_parity_exclude; uart_flow_control_enable; // configure reception uart_select_pin_as_RXD(PIN_UART_RXD); uart_interrupt_upon_RXDRDY_enable; uart_interrupt_upon_RXTO_enable; uart_interrupt_upon_ERROR_enable; uart_start_receiver; uart_enable; }
/** * @brief Initialise LED control pins */ void led_init() { nrf_drv_gpiote_out_config_t config = GPIOTE_CONFIG_OUT_SIMPLE(false); uint32_t pin; uint32_t err_code; /* Initialise RGB LED */ for(pin = LED_RED; pin <= LED_BLUE; pin++) { /* Set pin mode */ err_code = nrf_drv_gpiote_out_init(led_rgb_pin[pin], &config); APP_ERROR_CHECK(err_code); /* Configure high drive */ NRF_GPIO->PIN_CNF[led_rgb_pin[pin]] = (GPIO_PIN_CNF_DRIVE_H0S1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos); } nrf_gpio_pin_dir_set(2, NRF_GPIO_PIN_DIR_INPUT); nrf_gpio_cfg_input(2, NRF_GPIO_PIN_PULLUP); }
/* Function to init the connection manager */ void conn_init(void) { uint32_t err_code; int i; /* init "connection" pin */ nrf_gpio_pin_dir_set(CONN_PIN_NUMBER, NRF_GPIO_PIN_DIR_OUTPUT); /* init BLE stack */ ble_stack_init(true); /* init database discovery */ err_code = ble_db_discovery_init(); APP_ERROR_CHECK(err_code); /* init NUS client service */ nus_c_init(); /* init connection handle array */ for(i=0; i<NUM_OF_CONNECTIONS; i++) { active_conn_handles[i] = BLE_CONN_HANDLE_INVALID; } }
int main() { bool init_ok = false; //lint -save -e514 Unusual use of a boolean expression (use of &= assignment). // Configure input pins nrf_gpio_pin_dir_set(BUTTON_SEND_MOUSE_DATA, NRF_GPIO_PIN_DIR_INPUT); nrf_gpio_pin_dir_set(BUTTON_SEND_KEYBOARD_DATA, NRF_GPIO_PIN_DIR_INPUT); nrf_gpio_port_dir_set(LED_PORT, NRF_GPIO_PORT_DIR_OUTPUT); // Initialize and enable "mouse sensor" init_ok = mouse_sensor_init(MOUSE_SENSOR_SAMPLE_PERIOD_8_MS); mouse_sensor_enable(); // Initialize and enable Gazell init_ok &= nrf_gzll_init(NRF_GZLL_MODE_DEVICE); // Ensure Gazell parameters are configured. init_ok &= nrf_gzll_set_max_tx_attempts(150); init_ok &= nrf_gzll_set_device_channel_selection_policy(NRF_GZLLDE_DEVICE_CHANNEL_SELECTION_POLICY); init_ok &= nrf_gzll_set_timeslot_period(NRF_GZLLDE_RXPERIOD_DIV_2); init_ok &= nrf_gzll_set_sync_lifetime(0); // Asynchronous mode, more efficient for pairing. switch(gzp_get_pairing_status()) { case -2: host_id_received = false; system_addr_received = false; break; case -1: host_id_received = false; system_addr_received = true; break; default: host_id_received = true; system_addr_received = true; } gzp_init(); init_ok &= nrf_gzll_enable(); if(init_ok) { while(1) { // If BUTTON_SEND_MOUSE_DATA button is pressed. if(nrf_gpio_pin_read(BUTTON_SEND_MOUSE_DATA) == 0) { read_mouse_and_send(); } // If BUTTON_SEND_KEYBOARD_DATA button is pressed if(nrf_gpio_pin_read(BUTTON_SEND_KEYBOARD_DATA) == 0) { read_keyboard_and_send(); } /* CPU sleep. We will wake up from all enabled interrupts, which here are the internal Gazell interrupts and the "mouse sensor" internal timer interrupt. */ //__WFI(); } } else { /* The initialization failed. Use nrf_gzll_get_error_code() to investigate the cause. */ } //lint -restore }
/**@brief Function for initializing the GPIO pins as outputs */ static void gpio_init(void) { uint8_t gpios[12] = {R1, G1, B1, R2, G2, B2, A, B, C, LAT, CLK, OE}; for(uint8_t i = 0; i < 12; i++) nrf_gpio_pin_dir_set(gpios[i], NRF_GPIO_PIN_DIR_OUTPUT); }
void setup_led_pins() { nrf_gpio_pin_dir_set(PIN_LED_GREEN, NRF_GPIO_PIN_DIR_OUTPUT); nrf_gpio_pin_dir_set(PIN_LED_BLUE, NRF_GPIO_PIN_DIR_OUTPUT); nrf_gpio_pin_dir_set(PIN_LED_RED, NRF_GPIO_PIN_DIR_OUTPUT); }