Add platform nrf52
This commit is contained in:
67
src/driver.c
Normal file
67
src/driver.c
Normal file
@@ -0,0 +1,67 @@
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "driver.h"
|
||||
|
||||
int drv_open(const struct driver *drv)
|
||||
{
|
||||
int res = -1;
|
||||
assert(drv != NULL);
|
||||
|
||||
if(drv->fp->open) {
|
||||
res = drv->fp->open(drv);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int drv_close(const struct driver *drv)
|
||||
{
|
||||
int res = -1;
|
||||
assert(drv != NULL);
|
||||
|
||||
if(drv->fp->close) {
|
||||
res = drv->fp->close(drv);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int drv_read(const struct driver *drv, char *buffer, unsigned int length)
|
||||
{
|
||||
int res = -1;
|
||||
assert(drv != NULL);
|
||||
|
||||
if(drv->fp->read) {
|
||||
res = drv->fp->read(drv, buffer, length);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int drv_write(const struct driver *drv, const char *buffer, unsigned int length)
|
||||
{
|
||||
int res = -1;
|
||||
assert(drv != NULL);
|
||||
|
||||
if(drv->fp->write) {
|
||||
res = drv->fp->write(drv, buffer, length);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int drv_ioctl(const struct driver *drv, unsigned int cmd, unsigned int argc, ...)
|
||||
{
|
||||
int res = -1;
|
||||
assert(drv != NULL);
|
||||
|
||||
if(drv->fp->ioctl) {
|
||||
va_list args;
|
||||
va_start(args, argc);
|
||||
res = drv->fp->ioctl(drv, cmd, argc, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
81
src/main.c
81
src/main.c
@@ -1,77 +1,28 @@
|
||||
/**
|
||||
* 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 blinky_example_main main.c
|
||||
* @{
|
||||
* @ingroup blinky_example
|
||||
* @brief Blinky Example Application main file.
|
||||
*
|
||||
* This file contains the source code for a sample application to blink LEDs.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "nrf_delay.h"
|
||||
#include "boards.h"
|
||||
|
||||
/**
|
||||
* @brief Function for application main entry.
|
||||
*/
|
||||
#include "platform/narf52/narf52_dk.h"
|
||||
|
||||
#include "driver.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
/* Configure board. */
|
||||
bsp_board_init(BSP_INIT_LEDS);
|
||||
// bsp_board_init(BSP_INIT_LEDS);
|
||||
drv_open(&led_1);
|
||||
drv_open(&led_2);
|
||||
drv_open(&led_3);
|
||||
drv_open(&led_4);
|
||||
|
||||
/* Toggle LEDs. */
|
||||
while (true)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
bsp_board_led_invert(i);
|
||||
while(true) {
|
||||
for(uint32_t i = 0; i < UINT32_MAX; i++) {
|
||||
char x = 0x30 | (char)(1 & i);
|
||||
drv_write(&led_1, &x, 1);
|
||||
drv_write(&led_2, &x, 1);
|
||||
drv_write(&led_3, &x, 1);
|
||||
drv_write(&led_4, &x, 1);
|
||||
nrf_delay_ms(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*@}
|
||||
**/
|
82
src/platform/nrf52/gpio.c
Normal file
82
src/platform/nrf52/gpio.c
Normal file
@@ -0,0 +1,82 @@
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "platform/narf52/narf52.h"
|
||||
#include "platform/narf52/narf52_gpio.h"
|
||||
|
||||
#include "gpio.h"
|
||||
|
||||
int gpio_open(const struct driver *drv)
|
||||
{
|
||||
assert(NULL != drv);
|
||||
|
||||
int res = -1;
|
||||
struct narf52_gpio *this = (struct narf52_gpio *)(drv->dev);
|
||||
struct narf52_gpio_type *reg = (struct narf52_gpio_type *)NARF_P0_BASE;
|
||||
|
||||
reg->PIN_CNF[this->pin_number] = ((uint32_t)(this->dir) << 0)
|
||||
| ((uint32_t)(this->input) << 1)
|
||||
| ((uint32_t)(this->pull) << 2)
|
||||
| ((uint32_t)(this->drive) << 8)
|
||||
| ((uint32_t)(this->sense) << 16);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int gpio_close(const struct driver *drv)
|
||||
{
|
||||
assert(NULL != drv);
|
||||
int res = -1;
|
||||
struct gpio *this = (struct gpio *)(drv->dev);
|
||||
this = this;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int gpio_read(const struct driver *drv, char *buffer, unsigned int len)
|
||||
{
|
||||
assert((NULL != drv) && (buffer != NULL));
|
||||
if(len == 0) {
|
||||
return 0;
|
||||
}
|
||||
struct narf52_gpio *this = (struct narf52_gpio *)(drv->dev);
|
||||
struct narf52_gpio_type *reg = (struct narf52_gpio_type *)NARF_P0_BASE;
|
||||
uint32_t state = ((reg->IN) >> (this->pin_number) & 1UL);
|
||||
if(state) {
|
||||
buffer[0] = 0x31;
|
||||
} else {
|
||||
buffer[0] = 0x30;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int gpio_write(const struct driver *drv, const char *buffer, unsigned int len)
|
||||
{
|
||||
assert((NULL != drv) && (buffer != NULL));
|
||||
if(len == 0) {
|
||||
return 0;
|
||||
}
|
||||
struct narf52_gpio *this = (struct narf52_gpio *)(drv->dev);
|
||||
struct narf52_gpio_type *reg = (struct narf52_gpio_type *)NARF_P0_BASE;
|
||||
if(buffer[0] != 0x30) {
|
||||
reg->OUTSET = 1 << (this->pin_number);
|
||||
} else {
|
||||
reg->OUTCLR = 1 << (this->pin_number);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int gpio_ioctl(const struct driver *drv, unsigned int cmd, unsigned int argc, va_list args)
|
||||
{
|
||||
assert(drv != 0);
|
||||
|
||||
int res = -1;
|
||||
struct gpio *this = (struct gpio *)(drv->dev);
|
||||
this = this;
|
||||
|
||||
return res;
|
||||
}
|
Reference in New Issue
Block a user