Re-organize build system
This commit is contained in:
@@ -1,14 +1,30 @@
|
||||
#include <array>
|
||||
|
||||
#include "delay.h"
|
||||
#include "platform/hal.h"
|
||||
|
||||
using namespace hal;
|
||||
enum {
|
||||
PIN_NUMBER_LED_1 = 17,
|
||||
PIN_NUMBER_LED_2 = 18,
|
||||
PIN_NUMBER_LED_3 = 19,
|
||||
PIN_NUMBER_LED_4 = 20
|
||||
};
|
||||
|
||||
hal::Gpio led_1(PIN_NUMBER_LED_1);
|
||||
hal::Gpio led_2(PIN_NUMBER_LED_2);
|
||||
hal::Gpio led_3(PIN_NUMBER_LED_3);
|
||||
hal::Gpio led_4(PIN_NUMBER_LED_4);
|
||||
|
||||
std::array<hal::Gpio *, 4> leds = {&led_1, &led_2, &led_3, &led_4};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
Gpio led_1(17);
|
||||
while(true) {
|
||||
delay_ms(200);
|
||||
led_1.toggle();
|
||||
for(auto it = std::begin(leds); it != std::end(leds); ++it) {
|
||||
hal::Gpio * tmp = *it;
|
||||
tmp->toggle();
|
||||
delay_ms(500);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@@ -1,113 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2014 - 2019, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/** @file
|
||||
* @defgroup pin_change_int_example_main main.c
|
||||
* @{
|
||||
* @ingroup pin_change_int_example
|
||||
* @brief Pin Change Interrupt Example Application main file.
|
||||
*
|
||||
* This file contains the source code for a sample application using interrupts triggered by GPIO pins.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "nrf.h"
|
||||
#include "nrf_drv_gpiote.h"
|
||||
#include "app_error.h"
|
||||
#include "boards.h"
|
||||
|
||||
#ifdef BSP_BUTTON_0
|
||||
#define PIN_IN BSP_BUTTON_0
|
||||
#endif
|
||||
#ifndef PIN_IN
|
||||
#error "Please indicate input pin"
|
||||
#endif
|
||||
|
||||
#ifdef BSP_LED_0
|
||||
#define PIN_OUT BSP_LED_0
|
||||
#endif
|
||||
#ifndef PIN_OUT
|
||||
#error "Please indicate output pin"
|
||||
#endif
|
||||
|
||||
void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
|
||||
{
|
||||
nrf_drv_gpiote_out_toggle(PIN_OUT);
|
||||
}
|
||||
/**
|
||||
* @brief Function for configuring: PIN_IN pin for input, PIN_OUT pin for output,
|
||||
* and configures GPIOTE to give an interrupt on pin change.
|
||||
*/
|
||||
static void gpio_init(void)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
err_code = nrf_drv_gpiote_init();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
nrf_drv_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_SIMPLE(false);
|
||||
|
||||
err_code = nrf_drv_gpiote_out_init(PIN_OUT, &out_config);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);
|
||||
in_config.pull = NRF_GPIO_PIN_PULLUP;
|
||||
|
||||
err_code = nrf_drv_gpiote_in_init(PIN_IN, &in_config, in_pin_handler);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
nrf_drv_gpiote_in_event_enable(PIN_IN, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function for application main entry.
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
gpio_init();
|
||||
|
||||
while (true)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** @} */
|
10
src/delay.h
Normal file
10
src/delay.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef __DELAY_H__
|
||||
#define __DELAY_H__
|
||||
|
||||
#if defined(PLATFORM_nrf52)
|
||||
#include "nrf_delay.h"
|
||||
|
||||
#define delay_ms nrf_delay_ms
|
||||
#endif
|
||||
|
||||
#endif
|
@@ -1,7 +1,8 @@
|
||||
#include "platform/nrf52/gpio.h"
|
||||
|
||||
extern "C" {
|
||||
#include "nrf.h"
|
||||
#include "nrf52.h"
|
||||
#include "nrf52_bitfields.h"
|
||||
|
||||
NRF_GPIO_Type *const GPIO_REGS = reinterpret_cast<NRF_GPIO_Type *>(NRF_P0_BASE);
|
||||
}
|
||||
@@ -37,6 +38,11 @@ void Gpio::set_direction(direction dir)
|
||||
GPIO_REGS->PIN_CNF[pin_number] = direct | input | pull | drive | sense;
|
||||
}
|
||||
|
||||
void Gpio::set_pin_number(uint32_t pin)
|
||||
{
|
||||
this->pin_number = pin;
|
||||
}
|
||||
|
||||
uint32_t Gpio::get()
|
||||
{
|
||||
uint32_t res = (GPIO_REGS->IN >> pin_number) & 1UL;
|
||||
|
@@ -8,7 +8,9 @@ namespace platform::nrf52 {
|
||||
class Gpio : public interfaces::GpioInterface
|
||||
{
|
||||
public:
|
||||
explicit Gpio(uint32_t);
|
||||
inline Gpio() {}
|
||||
Gpio(uint32_t);
|
||||
void set_pin_number(uint32_t);
|
||||
void set_direction(direction) override;
|
||||
uint32_t get() override;
|
||||
void set() override;
|
||||
|
@@ -3,11 +3,10 @@
|
||||
#include "platform/nrf52/spi.h"
|
||||
|
||||
extern "C" {
|
||||
#include "nrf.h"
|
||||
#include "nrf52.h"
|
||||
#include "nrf52_bitfields.h"
|
||||
|
||||
NRF_SPI_Type *SPI_REGS = reinterpret_cast<NRF_SPI_Type *>(NRF_SPI0_BASE);
|
||||
// NRF_SPI_Type *const SPI_1_REGS = reinterpret_cast<NRF_SPI_Type *>(NRF_SPI1_BASE);
|
||||
// NRF_SPI_Type *const SPI_2_REGS = reinterpret_cast<NRF_SPI_Type *>(NRF_SPI2_BASE);
|
||||
}
|
||||
|
||||
using namespace platform::nrf52;
|
||||
@@ -28,9 +27,9 @@ Spi::Spi(uint32_t instance, uint32_t sck, uint32_t mosi, uint32_t miso, interfac
|
||||
this->chip_select.set();
|
||||
|
||||
SPI_REGS->ENABLE = 0;
|
||||
SPI_REGS->PSELSCK = sck;
|
||||
SPI_REGS->PSELMOSI = mosi;
|
||||
SPI_REGS->PSELMISO = miso;
|
||||
SPI_REGS->PSEL.SCK = sck;
|
||||
SPI_REGS->PSEL.MOSI = mosi;
|
||||
SPI_REGS->PSEL.MISO = miso;
|
||||
SPI_REGS->FREQUENCY = SPI_FREQUENCY_FREQUENCY_M8;
|
||||
|
||||
SPI_REGS->CONFIG = (0x03 << 1); //Sample on trailing edge of clock, shift serial data on leading edge, SCK polarity Active low
|
||||
@@ -53,13 +52,11 @@ void Spi::send(const uint8_t * buffer, uint32_t len)
|
||||
|
||||
void Spi::recv(uint8_t * buffer, uint32_t len)
|
||||
{
|
||||
//FIXME: missing CS handling
|
||||
|
||||
this->chip_select.clear();
|
||||
for(unsigned int i = 0; i < len; i++) {
|
||||
buffer[i] = this->transfer(buffer[i]);
|
||||
}
|
||||
|
||||
//FIXME: missing CS handling
|
||||
this->chip_select.set();
|
||||
}
|
||||
|
||||
uint32_t Spi::transfer(uint32_t data)
|
||||
|
Reference in New Issue
Block a user