Change stuff to theoretically work
This commit is contained in:
parent
d0d74daa2b
commit
2586a07064
|
@ -8,13 +8,15 @@
|
|||
#include "nrf_fprintf.h"
|
||||
|
||||
// LED definitions
|
||||
#define LED_PIN 7
|
||||
#define LED_BIT (1 << LED_PIN)
|
||||
#define REG_EN_PIN 15
|
||||
#define REG_EN_BIT (1 << REG_EN_PIN)
|
||||
#define PWR_EN_PIN 12
|
||||
#define PWR_EN_BIT (1 << PWR_EN_PIN)
|
||||
|
||||
// UART definitions
|
||||
#define UART_PIN_DISCONNECTED 0xFFFFFFFF
|
||||
#define UART_TX_PIN 15
|
||||
#define UART_RX_PIN 14
|
||||
#define UART_TX_PIN 18
|
||||
#define UART_RX_PIN 20
|
||||
#define UART_RTS_PIN UART_PIN_DISCONNECTED
|
||||
#define UART_CTS_PIN UART_PIN_DISCONNECTED
|
||||
#define UART_BAUD NRF_UART_BAUDRATE_115200
|
||||
|
@ -50,19 +52,17 @@ nrfx_uart_t nrfx_uart =
|
|||
NRF_UART0, 0
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int main(void) {
|
||||
uint32_t tix;
|
||||
|
||||
mstimeout(&tix, 0);
|
||||
init_gpio();
|
||||
init_serial();
|
||||
printf("\nNRF52 test\n");
|
||||
while (1)
|
||||
{
|
||||
if (mstimeout(&tix, 500))
|
||||
{
|
||||
NRF_GPIO->OUT ^= LED_BIT;
|
||||
NRF_GPIO->OUT |= PWR_EN_BIT;
|
||||
while (1) {
|
||||
if (mstimeout(&tix, 500)) {
|
||||
NRF_GPIO->OUT ^= REG_EN_BIT;
|
||||
putch('.');
|
||||
}
|
||||
poll_serial();
|
||||
|
@ -70,32 +70,27 @@ int main(void)
|
|||
}
|
||||
|
||||
// Initialise I/O port, and system tick counter
|
||||
void init_gpio(void)
|
||||
{
|
||||
nrf_gpio_cfg_output(LED_PIN);
|
||||
void init_gpio(void) {
|
||||
nrf_gpio_cfg_output(REG_EN_PIN);
|
||||
nrf_gpio_cfg_output(PWR_EN_PIN);
|
||||
nrf_drv_systick_init();
|
||||
}
|
||||
|
||||
// Check for timeout in milliseconds
|
||||
int mstimeout(uint32_t *tickp, uint32_t msec)
|
||||
{
|
||||
int mstimeout(uint32_t *tickp, uint32_t msec) {
|
||||
uint32_t t, diff;
|
||||
|
||||
t = nrf_systick_val_get();
|
||||
diff = NRF_SYSTICK_VAL_MASK & (systicks - t);
|
||||
|
||||
if (msec == 0)
|
||||
{
|
||||
if (msec == 0) {
|
||||
systicks = t;
|
||||
*tickp = msticks;
|
||||
}
|
||||
else if ((diff /= SystemCoreClock/1000) > 0)
|
||||
{
|
||||
} else if ((diff /= SystemCoreClock/1000) > 0) {
|
||||
systicks = t;
|
||||
msticks += diff;
|
||||
diff = msticks - *tickp;
|
||||
if (diff >= msec)
|
||||
{
|
||||
if (diff >= msec) {
|
||||
*tickp = msticks;
|
||||
return(1);
|
||||
}
|
||||
|
@ -104,8 +99,7 @@ int mstimeout(uint32_t *tickp, uint32_t msec)
|
|||
}
|
||||
|
||||
// Formatted print to serial port
|
||||
int printf(const char *fmt, ...)
|
||||
{
|
||||
int printf(const char *fmt, ...) {
|
||||
va_list args;
|
||||
int n;
|
||||
|
||||
|
@ -118,8 +112,7 @@ int printf(const char *fmt, ...)
|
|||
}
|
||||
|
||||
// Initialise serial I/O
|
||||
void init_serial(void)
|
||||
{
|
||||
void init_serial(void) {
|
||||
const nrfx_uart_config_t config = {
|
||||
UART_TX_PIN, UART_RX_PIN,
|
||||
UART_CTS_PIN, UART_RTS_PIN, 0,
|
||||
|
@ -129,12 +122,10 @@ void init_serial(void)
|
|||
}
|
||||
|
||||
// Poll serial interface, send next Tx char
|
||||
void poll_serial(void)
|
||||
{
|
||||
void poll_serial(void) {
|
||||
uint8_t b;
|
||||
|
||||
if (ser_txin!=ser_txout && !nrfx_uart_tx_in_progress(&nrfx_uart))
|
||||
{
|
||||
if (ser_txin!=ser_txout && !nrfx_uart_tx_in_progress(&nrfx_uart)) {
|
||||
b = ser_txbuff[ser_txout++];
|
||||
if (ser_txout >= SER_TX_BUFFLEN)
|
||||
ser_txout = 0;
|
||||
|
@ -144,14 +135,12 @@ void poll_serial(void)
|
|||
|
||||
// Add character to serial Tx circular buffer
|
||||
// Discard character if buffer is full
|
||||
int putch(int c)
|
||||
{
|
||||
int putch(int c) {
|
||||
int in=ser_txin+1;
|
||||
|
||||
if (in >= SER_TX_BUFFLEN)
|
||||
in = 0;
|
||||
if (in != ser_txout)
|
||||
{
|
||||
if (in != ser_txout) {
|
||||
ser_txbuff[ser_txin] = (uint8_t)c;
|
||||
ser_txin = in;
|
||||
}
|
||||
|
@ -159,15 +148,11 @@ int putch(int c)
|
|||
}
|
||||
|
||||
// Send data block to UART (via circular buffer)
|
||||
void uart_tx(void const *ctxp, char const *buff, size_t len)
|
||||
{
|
||||
void uart_tx(void const *ctxp, char const *buff, size_t len) {
|
||||
while (len--)
|
||||
putch(*buff++);
|
||||
}
|
||||
|
||||
// Dummy UART event handler
|
||||
void uart_event_handler(nrfx_uart_event_t const * evtp, void *ctxp)
|
||||
{
|
||||
void uart_event_handler(nrfx_uart_event_t const * evtp, void *ctxp) {
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
|
Loading…
Reference in New Issue