Add platform nrf52
This commit is contained in:
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