[stm32f429-discovery] General sweep to fix style according to make stylecheck.
This commit is contained in:
@@ -33,18 +33,21 @@
|
||||
static volatile uint32_t system_millis;
|
||||
|
||||
/* Called when systick fires */
|
||||
void sys_tick_handler(void) {
|
||||
void sys_tick_handler(void)
|
||||
{
|
||||
system_millis++;
|
||||
}
|
||||
|
||||
/* simple sleep for delay milliseconds */
|
||||
void msleep(uint32_t delay) {
|
||||
void msleep(uint32_t delay)
|
||||
{
|
||||
uint32_t wake = system_millis + delay;
|
||||
while (wake > system_millis) ;
|
||||
while (wake > system_millis);
|
||||
}
|
||||
|
||||
/* Getter function for the current time */
|
||||
uint32_t mtime(void) {
|
||||
uint32_t mtime(void)
|
||||
{
|
||||
return system_millis;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,10 +41,10 @@
|
||||
* read by the program. See the README file for a discussion of
|
||||
* the failure semantics.
|
||||
*/
|
||||
#define RECV_BUF_SIZE 128 // Arbitrary buffer size
|
||||
#define RECV_BUF_SIZE 128 /* Arbitrary buffer size */
|
||||
char recv_buf[RECV_BUF_SIZE];
|
||||
volatile int recv_ndx_nxt; // Next place to store
|
||||
volatile int recv_ndx_cur; // Next place to read
|
||||
volatile int recv_ndx_nxt; /* Next place to store */
|
||||
volatile int recv_ndx_cur; /* Next place to read */
|
||||
|
||||
/* For interrupt handling we add a new function which is called
|
||||
* when recieve interrupts happen. The name (usart1_isr) is created
|
||||
@@ -57,9 +57,10 @@ volatile int recv_ndx_cur; // Next place to read
|
||||
* right or it won't work. And you'll wonder where your interrupts
|
||||
* are going.
|
||||
*/
|
||||
void usart1_isr(void) {
|
||||
uint32_t reg;
|
||||
int i;
|
||||
void usart1_isr(void)
|
||||
{
|
||||
uint32_t reg;
|
||||
int i;
|
||||
|
||||
do {
|
||||
reg = USART_SR(CONSOLE_UART);
|
||||
@@ -68,21 +69,22 @@ void usart1_isr(void) {
|
||||
#ifdef RESET_ON_CTRLC
|
||||
/* Check for "reset" */
|
||||
if (recv_buf[recv_ndx_nxt] == '\003') {
|
||||
/* reset the system
|
||||
* volatile definition of return address on the stack
|
||||
* to insure it gets stored, changed to point to
|
||||
* the trampoline function (do_the_nasty) which is
|
||||
* required because we need to return of an interrupt
|
||||
* to get the internal value of the LR register reset
|
||||
* and put the processor back into "Thread" mode from
|
||||
* "Handler" mode.
|
||||
/* reset the system volatile definition of
|
||||
* return address on the stack to insure it
|
||||
* gets stored, changed to point to the
|
||||
* trampoline function (do_the_nasty) which is
|
||||
* required because we need to return of an
|
||||
* interrupt to get the internal value of the
|
||||
* LR register reset and put the processor back
|
||||
* into "Thread" mode from "Handler" mode.
|
||||
*
|
||||
* See the PM0214 Programming Manual for Cortex M,
|
||||
* pg 42, to see the format of the Cortex M4 stack after
|
||||
* an interrupt or exception has occurred.
|
||||
* See the PM0214 Programming Manual for Cortex
|
||||
* M, pg 42, to see the format of the Cortex M4
|
||||
* stack after an interrupt or exception has
|
||||
* occurred.
|
||||
*/
|
||||
volatile uint32_t *ret = (®) + 7;
|
||||
|
||||
|
||||
*ret = (uint32_t) &reset_handler;
|
||||
return;
|
||||
}
|
||||
@@ -93,7 +95,8 @@ void usart1_isr(void) {
|
||||
recv_ndx_nxt = i;
|
||||
}
|
||||
}
|
||||
} while ((reg & USART_SR_RXNE) != 0); // can read back-to-back interrupts
|
||||
} while ((reg & USART_SR_RXNE) != 0); /* can read back-to-back
|
||||
interrupts */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -102,7 +105,8 @@ void usart1_isr(void) {
|
||||
* Send the character 'c' to the USART, wait for the USART
|
||||
* transmit buffer to be empty first.
|
||||
*/
|
||||
void console_putc(char c) {
|
||||
void console_putc(char c)
|
||||
{
|
||||
uint32_t reg;
|
||||
do {
|
||||
reg = USART_SR(CONSOLE_UART);
|
||||
@@ -120,10 +124,11 @@ void console_putc(char c) {
|
||||
* The implementation is a bit different however, now it looks
|
||||
* in the ring buffer to see if a character has arrived.
|
||||
*/
|
||||
char console_getc(int wait) {
|
||||
char console_getc(int wait)
|
||||
{
|
||||
char c = 0;
|
||||
|
||||
while ((wait != 0) && (recv_ndx_cur == recv_ndx_nxt)) ;
|
||||
while ((wait != 0) && (recv_ndx_cur == recv_ndx_nxt));
|
||||
if (recv_ndx_cur != recv_ndx_nxt) {
|
||||
c = recv_buf[recv_ndx_cur];
|
||||
recv_ndx_cur = (recv_ndx_cur + 1) % RECV_BUF_SIZE;
|
||||
@@ -138,7 +143,8 @@ char console_getc(int wait) {
|
||||
* after the last character, as indicated by a NUL character, is
|
||||
* reached.
|
||||
*/
|
||||
void console_puts(char *s) {
|
||||
void console_puts(char *s)
|
||||
{
|
||||
while (*s != '\000') {
|
||||
console_putc(*s);
|
||||
/* Add in a carraige return, after sending line feed */
|
||||
@@ -156,7 +162,8 @@ void console_puts(char *s) {
|
||||
* support for editing characters (back space and delete)
|
||||
* end when a <CR> character is received.
|
||||
*/
|
||||
int console_gets(char *s, int len) {
|
||||
int console_gets(char *s, int len)
|
||||
{
|
||||
char *t = s;
|
||||
char c;
|
||||
|
||||
@@ -179,7 +186,7 @@ int console_gets(char *s, int len) {
|
||||
/* update end of string with NUL */
|
||||
*t = '\000';
|
||||
}
|
||||
return (t - s);
|
||||
return t - s;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -188,8 +195,8 @@ int console_gets(char *s, int len) {
|
||||
* Set the pins and clocks to create a console that we can
|
||||
* use for serial messages and getting text from the user.
|
||||
*/
|
||||
void console_setup(int baud) {
|
||||
|
||||
void console_setup(int baud)
|
||||
{
|
||||
/* MUST enable the GPIO clock in ADDITION to the USART clock */
|
||||
rcc_periph_clock_enable(RCC_GPIOA);
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
* These define sort of the minimum "library" of functions which
|
||||
* we can use on a serial port. If you wish to use a different
|
||||
* USART there are several things to change:
|
||||
* - CONSOLE_UART change this
|
||||
* - CONSOLE_UART change this
|
||||
* - Change the peripheral enable clock
|
||||
* - add usartx_isr for interrupts
|
||||
* - nvic_enable_interrupt(your choice of USART/UART)
|
||||
|
||||
@@ -36,21 +36,20 @@ void write_reg(uint8_t reg, uint8_t value);
|
||||
uint8_t read_xyz(int16_t vecs[3]);
|
||||
void spi_init(void);
|
||||
|
||||
|
||||
/*
|
||||
* Chart of the various SPI ports (1 - 6) and where their pins can be:
|
||||
|
||||
NSS SCK MISO MOSI
|
||||
-------------- ------------------- ------------- ---------------
|
||||
SPI1 PA4, PA15 PA5, PB3 PA6, PB4 PA7, PB5
|
||||
SPI2 PB9, PB12, PI0 PB10, PB13, PD3, PI1 PB14, PC2, PI2 PB15, PC3, PI3
|
||||
SPI3 PA15*, PA4* PB3*, PC10* PB4*, PC11* PB5*, PD6, PC12*
|
||||
SPI4 PE4,PE11 PE2, PE12 PE5, PE13 PE6, PE14
|
||||
SPI5 PF6, PH5 PF7, PH6 PF8 PF9, PF11, PH7
|
||||
SPI6 PG8 PG13 PG12 PG14
|
||||
|
||||
Pin name with * is alternate function 6 otherwise use alternate function 5.
|
||||
|
||||
*
|
||||
* NSS SCK MISO MOSI
|
||||
* -------------- ------------------- ------------- ---------------
|
||||
* SPI1 PA4, PA15 PA5, PB3 PA6, PB4 PA7, PB5
|
||||
* SPI2 PB9, PB12, PI0 PB10, PB13, PD3, PI1 PB14, PC2, PI2 PB15, PC3, PI3
|
||||
* SPI3 PA15*, PA4* PB3*, PC10* PB4*, PC11* PB5*, PD6, PC12*
|
||||
* SPI4 PE4,PE11 PE2, PE12 PE5, PE13 PE6, PE14
|
||||
* SPI5 PF6, PH5 PF7, PH6 PF8 PF9, PF11, PH7
|
||||
* SPI6 PG8 PG13 PG12 PG14
|
||||
*
|
||||
* Pin name with * is alternate function 6 otherwise use alternate function 5.
|
||||
*
|
||||
* MEMS uses SPI5 - SCK (PF7), MISO (PF8), MOSI (PF9),
|
||||
* MEMS CS* (PC1) -- GPIO
|
||||
* MEMS INT1 = PA1, MEMS INT2 = PA2
|
||||
@@ -60,13 +59,14 @@ void put_status(char *m);
|
||||
|
||||
/*
|
||||
* put_status(char *)
|
||||
*
|
||||
*
|
||||
* This is a helper function I wrote to watch the status register
|
||||
* it decodes the bits and prints them on the console. Sometimes
|
||||
* the SPI port comes up with the MODF flag set, you have to re-read
|
||||
* the status port and re-write the control register to clear that.
|
||||
*/
|
||||
void put_status(char *m) {
|
||||
void put_status(char *m)
|
||||
{
|
||||
uint16_t stmp;
|
||||
|
||||
console_puts(m);
|
||||
@@ -95,7 +95,7 @@ void put_status(char *m) {
|
||||
}
|
||||
console_puts("\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* read_reg(int reg)
|
||||
*
|
||||
@@ -106,10 +106,11 @@ void put_status(char *m) {
|
||||
* be a more stable solution.
|
||||
*/
|
||||
uint16_t
|
||||
read_reg(int reg) {
|
||||
read_reg(int reg)
|
||||
{
|
||||
uint16_t d1, d2;
|
||||
|
||||
d1 = 0x80 | (reg & 0x3f); // Read operation
|
||||
d1 = 0x80 | (reg & 0x3f); /* Read operation */
|
||||
/* Nominallly a register read is a 16 bit operation */
|
||||
gpio_clear(GPIOC, GPIO1);
|
||||
spi_send(SPI5, d1);
|
||||
@@ -136,22 +137,23 @@ read_reg(int reg) {
|
||||
* Then the status register is read and returned.
|
||||
*/
|
||||
uint8_t
|
||||
read_xyz(int16_t vecs[3]) {
|
||||
read_xyz(int16_t vecs[3])
|
||||
{
|
||||
uint8_t buf[7];
|
||||
int i;
|
||||
|
||||
gpio_clear(GPIOC, GPIO1); // CS* select
|
||||
gpio_clear(GPIOC, GPIO1); /* CS* select */
|
||||
spi_send(SPI5, 0xc0 | 0x28);
|
||||
(void) spi_read(SPI5);
|
||||
for (i = 0; i < 6; i++) {
|
||||
spi_send(SPI5, 0);
|
||||
buf[i] = spi_read(SPI5);
|
||||
}
|
||||
gpio_set(GPIOC, GPIO1); // CS* deselect
|
||||
gpio_set(GPIOC, GPIO1); /* CS* deselect */
|
||||
vecs[0] = (buf[1] << 8 | buf[0]);
|
||||
vecs[1] = (buf[3] << 8 | buf[2]);
|
||||
vecs[3] = (buf[5] << 8 | buf[4]);
|
||||
return read_reg(0x27); // Status register
|
||||
return read_reg(0x27); /* Status register */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -161,13 +163,14 @@ read_xyz(int16_t vecs[3]) {
|
||||
* selecting it and then writing to it.
|
||||
*/
|
||||
void
|
||||
write_reg(uint8_t reg, uint8_t value) {
|
||||
gpio_clear(GPIOC, GPIO1); // CS* select
|
||||
write_reg(uint8_t reg, uint8_t value)
|
||||
{
|
||||
gpio_clear(GPIOC, GPIO1); /* CS* select */
|
||||
spi_send(SPI5, reg);
|
||||
(void) spi_read(SPI5);
|
||||
spi_send(SPI5, value);
|
||||
(void) spi_read(SPI5);
|
||||
gpio_set(GPIOC, GPIO1); // CS* deselect
|
||||
gpio_set(GPIOC, GPIO1); /* CS* deselect */
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -180,7 +183,8 @@ int print_decimal(int);
|
||||
* number on the console.
|
||||
*/
|
||||
int
|
||||
print_decimal(int num) {
|
||||
print_decimal(int num)
|
||||
{
|
||||
int ndx = 0;
|
||||
char buf[10];
|
||||
int len = 0;
|
||||
@@ -204,7 +208,7 @@ print_decimal(int num) {
|
||||
console_putc(buf[ndx--]);
|
||||
len++;
|
||||
}
|
||||
return len; // number of characters printed
|
||||
return len; /* number of characters printed */
|
||||
}
|
||||
|
||||
char *axes[] = { "X: ", "Y: ", "Z: " };
|
||||
@@ -214,7 +218,8 @@ char *axes[] = { "X: ", "Y: ", "Z: " };
|
||||
* SPI port, and then shows a continuous display of values on
|
||||
* the console once you start it. Typing ^C will reset it.
|
||||
*/
|
||||
int main(void) {
|
||||
int main(void)
|
||||
{
|
||||
int16_t vecs[3];
|
||||
int16_t baseline[3];
|
||||
int tmp, i;
|
||||
@@ -225,13 +230,13 @@ int main(void) {
|
||||
console_setup(115200);
|
||||
|
||||
/* Enable the GPIO ports whose pins we are using */
|
||||
rcc_periph_clock_enable(RCC_GPIOF | RCC_GPIOC);
|
||||
rcc_periph_clock_enable(RCC_GPIOF | RCC_GPIOC);
|
||||
|
||||
gpio_mode_setup(GPIOF, GPIO_MODE_AF, GPIO_PUPD_PULLDOWN,
|
||||
GPIO7 | GPIO8 | GPIO9);
|
||||
GPIO7 | GPIO8 | GPIO9);
|
||||
gpio_set_af(GPIOF, GPIO_AF5, GPIO7 | GPIO8 | GPIO9);
|
||||
gpio_set_output_options(GPIOF, GPIO_OTYPE_PP, GPIO_OSPEED_25MHZ,
|
||||
GPIO7 | GPIO9);
|
||||
GPIO7 | GPIO9);
|
||||
|
||||
/* Chip select line */
|
||||
gpio_set(GPIOC, GPIO1);
|
||||
@@ -239,11 +244,11 @@ int main(void) {
|
||||
|
||||
rcc_periph_clock_enable(RCC_SPI5);
|
||||
|
||||
cr_tmp = SPI_CR1_BAUDRATE_FPCLK_DIV_8 |\
|
||||
SPI_CR1_MSTR |\
|
||||
SPI_CR1_SPE |\
|
||||
SPI_CR1_CPHA |\
|
||||
SPI_CR1_CPOL_CLK_TO_1_WHEN_IDLE ;
|
||||
cr_tmp = SPI_CR1_BAUDRATE_FPCLK_DIV_8 |
|
||||
SPI_CR1_MSTR |
|
||||
SPI_CR1_SPE |
|
||||
SPI_CR1_CPHA |
|
||||
SPI_CR1_CPOL_CLK_TO_1_WHEN_IDLE;
|
||||
|
||||
put_status("\nBefore init: ");
|
||||
SPI_CR2(SPI5) |= SPI_CR2_SSOE;
|
||||
@@ -269,25 +274,25 @@ int main(void) {
|
||||
* temperature reading is correct and the ID code returned is
|
||||
* as expected so the SPI code at least is working.
|
||||
*/
|
||||
write_reg(0x20, 0xcf); // Normal mode
|
||||
write_reg(0x21, 0x07); // standard filters
|
||||
write_reg(0x23, 0xb0); // 250 dps
|
||||
write_reg(0x20, 0xcf); /* Normal mode */
|
||||
write_reg(0x21, 0x07); /* standard filters */
|
||||
write_reg(0x23, 0xb0); /* 250 dps */
|
||||
tmp = (int) read_reg(0x26);
|
||||
console_puts( "Temperature: ");
|
||||
console_puts("Temperature: ");
|
||||
print_decimal(tmp);
|
||||
console_puts( " C\n");
|
||||
|
||||
console_puts(" C\n");
|
||||
|
||||
count = 0;
|
||||
while (1) {
|
||||
tmp = read_xyz(vecs);
|
||||
for (i = 0; i < 3; i++) {
|
||||
int pad;
|
||||
console_puts( axes[i]);
|
||||
console_puts(axes[i]);
|
||||
tmp = vecs[i] - baseline[i];
|
||||
pad = print_decimal(tmp);
|
||||
pad = 15 - pad;
|
||||
while (pad--) {
|
||||
console_puts( " ");
|
||||
console_puts(" ");
|
||||
}
|
||||
}
|
||||
console_putc('\r');
|
||||
|
||||
Reference in New Issue
Block a user