한글 블로그로 보기
main.c
- #include <stdbool.h>
- #include <stdint.h>
- #include "nrf_delay.h"
- #include "nrf_gpio.h"
- #include "boards.h"
- const uint8_t leds_list[LEDS_NUMBER] = LEDS_LIST;
- /**
- * @brief Function for application main entry.
- */
- int main(void)
- {
- // Configure LED-pins as outputs.
- LEDS_CONFIGURE(LEDS_MASK);
- // Toggle LEDs.
- while (true)
- {
- for (int i = 0; i < LEDS_NUMBER; i++)
- {
- LEDS_INVERT(1 << leds_list[i]);
- nrf_delay_ms(500);
- }
- }
- }
Line 7 : declared LED array.
LEDS_NUMBER and LEDS_LIST in pca10028.h
Line 15 : Config LED(setting port output)
LEDS_CONFIGURE in board.h LEDS_MASK in pca10028.h
Line 22 : Toggle for LED. LEDS_INVERT in board.h
Line 23 : Delay. nrf_delay_ms in nrf_delay.c
pca10028.h
- #define LEDS_NUMBER 4
- #define LED_START 21
- #define LED_1 21
- #define LED_2 22
- #define LED_3 23
- #define LED_4 24
- #define LED_STOP 24
- #define LEDS_LIST { LED_1, LED_2, LED_3, LED_4 }
- #define BSP_LED_0 LED_1
- #define BSP_LED_1 LED_2
- #define BSP_LED_2 LED_3
- #define BSP_LED_3 LED_4
- #define BSP_LED_0_MASK (1<<BSP_LED_0)
- #define BSP_LED_1_MASK (1<<BSP_LED_1)
- #define BSP_LED_2_MASK (1<<BSP_LED_2)
- #define BSP_LED_3_MASK (1<<BSP_LED_3)
- #define LEDS_MASK (BSP_LED_0_MASK | BSP_LED_1_MASK | BSP_LED_2_MASK | BSP_LED_3_MASK)
- /* all LEDs are lit when GPIO is low */
board.h
- #define LEDS_INVERT(leds_mask) do { uint32_t gpio_state = NRF_GPIO->OUT; \
- NRF_GPIO->OUTSET = ((leds_mask) & ~gpio_state); \
- NRF_GPIO->OUTCLR = ((leds_mask) & gpio_state); } while (0)
- #define LEDS_CONFIGURE(leds_mask) do { uint32_t pin; \
- for (pin = 0; pin < 32; pin++) \
- if ( (leds_mask) & (1 << pin) ) \
- nrf_gpio_cfg_output(pin); } while (0)
nrf_delay.c
- void nrf_delay_ms(uint32_t volatile number_of_ms)
- {
- while(number_of_ms != 0)
- {
- number_of_ms--;
- nrf_delay_us(999);
- }
- }
No comments:
Post a Comment