examples: Even more coding-style fixes.

This commit is contained in:
Uwe Hermann 2011-11-13 17:07:21 +01:00
parent c3fea659d1
commit bb8741a79b
31 changed files with 157 additions and 175 deletions

View File

@ -170,7 +170,7 @@ static int cdcacm_control_request(struct usb_setup_data *req, u8 **buf,
(void)complete; (void)complete;
(void)buf; (void)buf;
switch(req->bRequest) { switch (req->bRequest) {
case USB_CDC_REQ_SET_CONTROL_LINE_STATE: { case USB_CDC_REQ_SET_CONTROL_LINE_STATE: {
/* /*
* This Linux cdc_acm driver requires this to be implemented * This Linux cdc_acm driver requires this to be implemented

View File

@ -367,25 +367,25 @@ int main(void)
TIM1_CCR1 = gamma_table_linear[j0]; TIM1_CCR1 = gamma_table_linear[j0];
j0 += d0; j0 += d0;
if (j0 == 255) if (j0 == 255)
d0 =- 1; d0 = -1;
if (j0 == 0) if (j0 == 0)
d0 = 1; d0 = 1;
TIM1_CCR2 = gamma_table_1_3[j1]; TIM1_CCR2 = gamma_table_1_3[j1];
j1 += d1; j1 += d1;
if (j1 == 255) if (j1 == 255)
d1 =- 1; d1 = -1;
if (j1 == 0) if (j1 == 0)
d1 = 1; d1 = 1;
TIM1_CCR3 = gamma_table_2_5[j2]; TIM1_CCR3 = gamma_table_2_5[j2];
j2 += d2; j2 += d2;
if (j2 == 255) if (j2 == 255)
d2 =- 1; d2 = -1;
if (j2 == 0) if (j2 == 0)
d2 = 1; d2 = 1;
TIM1_CCR4= gamma_table_3_0[j3]; TIM1_CCR4 = gamma_table_3_0[j3];
j3 += d3; j3 += d3;
if (j3 == 255) if (j3 == 255)
d3 =- 1; d3 = -1;
if (j3 == 0) if (j3 == 0)
d3 = 1; d3 = 1;
for (i = 0; i < 50000; i++); for (i = 0; i < 50000; i++);
@ -405,25 +405,25 @@ int main(void)
TIM1_CCR1 = GAMMA_TABLE[j0]; TIM1_CCR1 = GAMMA_TABLE[j0];
j0 += d0; j0 += d0;
if (j0 == 255) if (j0 == 255)
d0 =- 1; d0 = -1;
if (j0 == 0) if (j0 == 0)
d0 = 1; d0 = 1;
TIM1_CCR2 = GAMMA_TABLE[j1]; TIM1_CCR2 = GAMMA_TABLE[j1];
j1 += d1; j1 += d1;
if (j1 == 255) if (j1 == 255)
d1 =- 1; d1 = - 1;
if (j1 == 0) if (j1 == 0)
d1 = 1; d1 = 1;
TIM1_CCR3 = GAMMA_TABLE[j2]; TIM1_CCR3 = GAMMA_TABLE[j2];
j2 += d2; j2 += d2;
if (j2 == 255) if (j2 == 255)
d2 =- 1; d2 = -1;
if (j2 == 0) if (j2 == 0)
d2 = 1; d2 = 1;
TIM1_CCR4 = GAMMA_TABLE[j3]; TIM1_CCR4 = GAMMA_TABLE[j3];
j3 += d3; j3 += d3;
if (j3 == 255) if (j3 == 255)
d3 =- 1; d3 = -1;
if (j3 == 0) if (j3 == 0)
d3 = 1; d3 = 1;
for (i = 0; i < 10000; i++); for (i = 0; i < 10000; i++);
@ -446,25 +446,25 @@ int main(void)
TIM1_CCR1 = GAMMA_TABLE[j0]; TIM1_CCR1 = GAMMA_TABLE[j0];
j0 += d0; j0 += d0;
if (j0 == 255) if (j0 == 255)
d0 =- 1; d0 = -1;
if (j0 == 19) if (j0 == 19)
j0 = 20; j0 = 20;
TIM1_CCR2 = GAMMA_TABLE[j1]; TIM1_CCR2 = GAMMA_TABLE[j1];
j1 += d1; j1 += d1;
if (j1 == 255) if (j1 == 255)
d1 =- 1; d1 = -1;
if (j1 == 19) if (j1 == 19)
j1 = 20; j1 = 20;
TIM1_CCR3 = GAMMA_TABLE[j2]; TIM1_CCR3 = GAMMA_TABLE[j2];
j2 += d2; j2 += d2;
if (j2 == 255) if (j2 == 255)
d2 =- 1; d2 = -1;
if (j2 == 19) if (j2 == 19)
j2 = 20; j2 = 20;
TIM1_CCR4 = GAMMA_TABLE[j3]; TIM1_CCR4 = GAMMA_TABLE[j3];
j3 += d3; j3 += d3;
if (j3 == 255) if (j3 == 255)
d3 =- 1; d3 = -1;
if (j3 == 19) if (j3 == 19)
j3 = 20; j3 = 20;
for (i = 0; i < 5000; i++); for (i = 0; i < 5000; i++);
@ -486,7 +486,7 @@ int main(void)
break; break;
} }
if (k == 3) if (k == 3)
kd =- 1; kd = -1;
if (k == 0) if (k == 0)
kd = 1; kd = 1;
} }

View File

@ -258,8 +258,7 @@ void gpio_setup(void)
*/ */
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL,
GPIO_TIM3_CH1 | GPIO_TIM3_CH1 | GPIO_TIM3_CH2);
GPIO_TIM3_CH2);
/* /*
* Set GPIO0 and 1 (in GPIO port B) to * Set GPIO0 and 1 (in GPIO port B) to
@ -267,8 +266,7 @@ void gpio_setup(void)
*/ */
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL,
GPIO_TIM3_CH3 | GPIO_TIM3_CH3 | GPIO_TIM3_CH4);
GPIO_TIM3_CH4);
} }
void tim_setup(void) void tim_setup(void)
@ -354,25 +352,25 @@ int main(void)
TIM3_CCR1 = gamma_table_linear[j0]; TIM3_CCR1 = gamma_table_linear[j0];
j0 += d0; j0 += d0;
if (j0 == 255) if (j0 == 255)
d0 =- 1; d0 = -1;
if (j0 == 0) if (j0 == 0)
d0 = 1; d0 = 1;
TIM3_CCR2 = gamma_table_1_3[j1]; TIM3_CCR2 = gamma_table_1_3[j1];
j1 += d1; j1 += d1;
if (j1 == 255) if (j1 == 255)
d1 =- 1; d1 = -1;
if (j1 == 0) if (j1 == 0)
d1 = 1; d1 = 1;
TIM3_CCR3 = gamma_table_2_5[j2]; TIM3_CCR3 = gamma_table_2_5[j2];
j2 += d2; j2 += d2;
if (j2 == 255) if (j2 == 255)
d2 =- 1; d2 = -1;
if (j2 == 0) if (j2 == 0)
d2 = 1; d2 = 1;
TIM3_CCR4= gamma_table_3_0[j3]; TIM3_CCR4 = gamma_table_3_0[j3];
j3 += d3; j3 += d3;
if (j3 == 255) if (j3 == 255)
d3 =- 1; d3 = -1;
if (j3 == 0) if (j3 == 0)
d3 = 1; d3 = 1;
for (i = 0; i < 50000; i++); for (i = 0; i < 50000; i++);
@ -392,25 +390,25 @@ int main(void)
TIM3_CCR1 = GAMMA_TABLE[j0]; TIM3_CCR1 = GAMMA_TABLE[j0];
j0 += d0; j0 += d0;
if (j0 == 255) if (j0 == 255)
d0 =- 1; d0 = -1;
if (j0 == 0) if (j0 == 0)
d0 = 1; d0 = 1;
TIM3_CCR2 = GAMMA_TABLE[j1]; TIM3_CCR2 = GAMMA_TABLE[j1];
j1 += d1; j1 += d1;
if (j1 == 255) if (j1 == 255)
d1 =- 1; d1 = -1;
if (j1 == 0) if (j1 == 0)
d1 = 1; d1 = 1;
TIM3_CCR3 = GAMMA_TABLE[j2]; TIM3_CCR3 = GAMMA_TABLE[j2];
j2 += d2; j2 += d2;
if (j2 == 255) if (j2 == 255)
d2 =- 1; d2 = -1;
if (j2 == 0) if (j2 == 0)
d2 = 1; d2 = 1;
TIM3_CCR4 = GAMMA_TABLE[j3]; TIM3_CCR4 = GAMMA_TABLE[j3];
j3 += d3; j3 += d3;
if (j3 == 255) if (j3 == 255)
d3 =- 1; d3 = -1;
if (j3 == 0) if (j3 == 0)
d3 = 1; d3 = 1;
for (i = 0; i < 10000; i++); for (i = 0; i < 10000; i++);
@ -433,25 +431,25 @@ int main(void)
TIM3_CCR1 = GAMMA_TABLE[j0]; TIM3_CCR1 = GAMMA_TABLE[j0];
j0 += d0; j0 += d0;
if (j0 == 255) if (j0 == 255)
d0 =- 1; d0 = -1;
if (j0 == 19) if (j0 == 19)
j0 = 20; j0 = 20;
TIM3_CCR2 = GAMMA_TABLE[j1]; TIM3_CCR2 = GAMMA_TABLE[j1];
j1 += d1; j1 += d1;
if (j1 == 255) if (j1 == 255)
d1 =- 1; d1 = -1;
if (j1 == 19) if (j1 == 19)
j1 = 20; j1 = 20;
TIM3_CCR3 = GAMMA_TABLE[j2]; TIM3_CCR3 = GAMMA_TABLE[j2];
j2 += d2; j2 += d2;
if (j2 == 255) if (j2 == 255)
d2 =- 1; d2 = -1;
if (j2 == 19) if (j2 == 19)
j2 = 20; j2 = 20;
TIM3_CCR4 = GAMMA_TABLE[j3]; TIM3_CCR4 = GAMMA_TABLE[j3];
j3 += d3; j3 += d3;
if (j3 == 255) if (j3 == 255)
d3 =- 1; d3 = -1;
if (j3 == 19) if (j3 == 19)
j3 = 20; j3 = 20;
for (i = 0; i < 15000; i++) for (i = 0; i < 15000; i++)
@ -474,7 +472,7 @@ int main(void)
break; break;
} }
if (k == 3) if (k == 3)
kd =- 1; kd = -1;
if (k == 0) if (k == 0)
kd = 1; kd = 1;
} }

View File

@ -128,7 +128,7 @@ int main(void)
temperature = stts75_read_temperature(I2C2, STTS75_SENSOR0); temperature = stts75_read_temperature(I2C2, STTS75_SENSOR0);
/* Send the temperature as binary over USART1. */ /* Send the temperature as binary over USART1. */
for (i = 15; i >= 0 ; i--) { for (i = 15; i >= 0; i--) {
if (temperature & (1 << i)) if (temperature & (1 << i))
usart_send(USART1, '1'); usart_send(USART1, '1');
else else

View File

@ -140,7 +140,7 @@ u16 stts75_read_temperature(u32 i2c, u8 sensor)
reg32 = I2C_SR2(i2c); reg32 = I2C_SR2(i2c);
i2c_send_data(i2c, 0x0); /* temperature register */ i2c_send_data(i2c, 0x0); /* temperature register */
while (!(I2C_SR1(i2c) & (I2C_SR1_BTF|I2C_SR1_TxE))); while (!(I2C_SR1(i2c) & (I2C_SR1_BTF | I2C_SR1_TxE)));
/* /*
* Now we transferred that we want to ACCESS the temperature register. * Now we transferred that we want to ACCESS the temperature register.

View File

@ -19,7 +19,6 @@
#include <libopencm3/stm32/f1/rcc.h> #include <libopencm3/stm32/f1/rcc.h>
#include <libopencm3/stm32/f1/gpio.h> #include <libopencm3/stm32/f1/gpio.h>
#include <libopencm3/usb/usbd.h> #include <libopencm3/usb/usbd.h>
const struct usb_device_descriptor dev = { const struct usb_device_descriptor dev = {
@ -73,7 +72,7 @@ const char *usb_strings[] = {
"x", "x",
"Black Sphere Technologies", "Black Sphere Technologies",
"Simple Device", "Simple Device",
"1001" "1001",
}; };
static int simple_control_callback(struct usb_setup_data *req, u8 **buf, static int simple_control_callback(struct usb_setup_data *req, u8 **buf,
@ -83,10 +82,10 @@ static int simple_control_callback(struct usb_setup_data *req, u8 **buf,
(void)len; (void)len;
(void)complete; (void)complete;
if(req->bmRequestType != 0x40) if (req->bmRequestType != 0x40)
return 0; /* Only accept vendor request */ return 0; /* Only accept vendor request. */
if(req->wValue & 1) if (req->wValue & 1)
gpio_set(GPIOC, GPIO6); gpio_set(GPIOC, GPIO6);
else else
gpio_clear(GPIOC, GPIO6); gpio_clear(GPIOC, GPIO6);

View File

@ -45,8 +45,7 @@ void button_setup(void)
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
/* Set GPIO0 (in GPIO port A) to 'input open-drain'. */ /* Set GPIO0 (in GPIO port A) to 'input open-drain'. */
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO0);
GPIO_CNF_INPUT_FLOAT, GPIO0);
} }
int main(void) int main(void)

View File

@ -33,8 +33,8 @@ void gpio_setup(void)
// GPIOC_CRH = (GPIO_CNF_OUTPUT_PUSHPULL << (((12 - 8) * 4) + 2)); // GPIOC_CRH = (GPIO_CNF_OUTPUT_PUSHPULL << (((12 - 8) * 4) + 2));
// GPIOC_CRH |= (GPIO_MODE_OUTPUT_2_MHZ << ((12 - 8) * 4)); // GPIOC_CRH |= (GPIO_MODE_OUTPUT_2_MHZ << ((12 - 8) * 4));
/* Using API functions: */ /* Using API functions: */
MMIO32(RCC_BASE+0x30) |= (1<<2); MMIO32(RCC_BASE + 0x30) |= (1 << 2);
gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO3|GPIO4); gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO3 | GPIO4);
} }
int main(void) int main(void)

View File

@ -18,32 +18,32 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stdio.h>
#include <errno.h>
#include <libopencm3/stm32/spi.h> #include <libopencm3/stm32/spi.h>
#include <libopencm3/stm32/usart.h> #include <libopencm3/stm32/usart.h>
#include <libopencm3/stm32/nvic.h> #include <libopencm3/stm32/nvic.h>
#include <libopencm3/stm32/f2/gpio.h> #include <libopencm3/stm32/f2/gpio.h>
#include <libopencm3/stm32/f2/rcc.h> #include <libopencm3/stm32/f2/rcc.h>
#include <stdio.h>
#include <errno.h>
void clock_setup(void) void clock_setup(void)
{ {
RCC_APB1ENR |= RCC_APB1ENR_SPI2EN; RCC_APB1ENR |= RCC_APB1ENR_SPI2EN;
RCC_APB2ENR |= RCC_APB2ENR_USART1EN; RCC_APB2ENR |= RCC_APB2ENR_USART1EN;
RCC_AHB1ENR |= RCC_AHB1ENR_IOPCEN | RCC_AHB1ENR_IOPAEN | RCC_AHB1ENR_IOPBEN; RCC_AHB1ENR |=
RCC_AHB1ENR_IOPCEN | RCC_AHB1ENR_IOPAEN | RCC_AHB1ENR_IOPBEN;
} }
void spi_setup(void) void spi_setup(void)
{ {
gpio_mode_setup(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO13 | GPIO14 | GPIO15); gpio_mode_setup(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE,
GPIO13 | GPIO14 | GPIO15);
gpio_set_af(GPIOB, GPIO_AF5, GPIO13 | GPIO14 | GPIO15); gpio_set_af(GPIOB, GPIO_AF5, GPIO13 | GPIO14 | GPIO15);
/* Setup SPI parameters. */ /* Setup SPI parameters. */
spi_init_master(SPI2, SPI_CR1_BAUDRATE_FPCLK_DIV_256, SPI_CR1_CPOL, \ spi_init_master(SPI2, SPI_CR1_BAUDRATE_FPCLK_DIV_256, SPI_CR1_CPOL,
SPI_CR1_CPHA, SPI_CR1_DFF_8BIT, SPI_CR1_MSBFIRST); SPI_CR1_CPHA, SPI_CR1_DFF_8BIT, SPI_CR1_MSBFIRST);
spi_enable_ss_output(SPI2); /* Required, see 25.3.1 section about NSS */ spi_enable_ss_output(SPI2); /* Required, see NSS, 25.3.1 section. */
/* Finally enable the SPI. */ /* Finally enable the SPI. */
spi_enable(SPI2); spi_enable(SPI2);
@ -52,7 +52,7 @@ void spi_setup(void)
void usart_setup(void) void usart_setup(void)
{ {
gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9); gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9);
gpio_set_af(GPIOA, GPIO_AF7, GPIO9|GPIO10); gpio_set_af(GPIOA, GPIO_AF7, GPIO9 | GPIO10);
/* Setup UART parameters. */ /* Setup UART parameters. */
usart_set_baudrate(USART1, 9600, 16000000); usart_set_baudrate(USART1, 9600, 16000000);
@ -70,19 +70,17 @@ void gpio_setup(void)
{ {
gpio_set(GPIOC, GPIO3); gpio_set(GPIOC, GPIO3);
/* Setup GPIO3 (in GPIO port C) for led use. */ /* Setup GPIO3 (in GPIO port C) for LED use. */
gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT, gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT, GPIO_MODE_OUTPUT, GPIO3);
GPIO_MODE_OUTPUT, GPIO3);
} }
int _write (int file, char *ptr, int len) int _write(int file, char *ptr, int len)
{ {
int i; int i;
if (file == 1) { if (file == 1) {
for (i = 0; i < len; i++){ for (i = 0; i < len; i++)
usart_send_blocking(USART1, ptr[i]); usart_send_blocking(USART1, ptr[i]);
}
return i; return i;
} }
errno = EIO; errno = EIO;
@ -99,15 +97,16 @@ int main(void)
usart_setup(); usart_setup();
spi_setup(); spi_setup();
while (1) while (1) {
{
counter++; counter++;
printf("Hello, world! %i\r\n", counter); printf("Hello, world! %i\r\n", counter);
dummy = spi_read(SPI2); /* Stops RX buff overflow, but probably not needed */ /* Stops RX buffer overflow, but probably not needed. */
spi_send(SPI2,(u8)counter); dummy = spi_read(SPI2);
spi_send(SPI2, (u8) counter);
gpio_toggle(GPIOC, GPIO3); gpio_toggle(GPIOC, GPIO3);
} }
while(1); while (1);
return 0; return 0;
} }

View File

@ -34,9 +34,8 @@ void clock_setup(void)
//rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN); //rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
/* Enable clocks for GPIO port A (for GPIO_USART1_TX) and USART1. */ /* Enable clocks for GPIO port A (for GPIO_USART1_TX) and USART1. */
//rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN | // rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN |
// RCC_APB2ENR_AFIOEN | // RCC_APB2ENR_AFIOEN | RCC_APB2ENR_USART1EN);
// RCC_APB2ENR_USART1EN);
RCC_APB2ENR |= RCC_APB2ENR_USART1EN; RCC_APB2ENR |= RCC_APB2ENR_USART1EN;
RCC_AHB1ENR |= RCC_AHB1ENR_IOPCEN | RCC_AHB1ENR_IOPAEN; RCC_AHB1ENR |= RCC_AHB1ENR_IOPCEN | RCC_AHB1ENR_IOPAEN;
} }
@ -44,7 +43,7 @@ void clock_setup(void)
void usart_setup(void) void usart_setup(void)
{ {
gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9); gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9);
gpio_set_af(GPIOA, GPIO_AF7, GPIO9|GPIO10); gpio_set_af(GPIOA, GPIO_AF7, GPIO9 | GPIO10);
/* Setup UART parameters. */ /* Setup UART parameters. */
usart_set_baudrate(USART1, 9600, 16000000); usart_set_baudrate(USART1, 9600, 16000000);
@ -62,20 +61,17 @@ void gpio_setup(void)
{ {
gpio_set(GPIOC, GPIO3); gpio_set(GPIOC, GPIO3);
/* Setup GPIO6 and 7 (in GPIO port A) for led use. */ /* Setup GPIO6 and 7 (in GPIO port A) for LED use. */
gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT, gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT, GPIO_MODE_OUTPUT, GPIO3);
GPIO_MODE_OUTPUT, GPIO3);
} }
int _write (int file, char *ptr, int len) int _write(int file, char *ptr, int len)
{ {
int i; int i;
if (file == 1) { if (file == 1) {
for (i = 0; i < len; i++){ for (i = 0; i < len; i++)
usart_send_blocking(USART1, ptr[i]); usart_send_blocking(USART1, ptr[i]);
}
return i; return i;
} }
@ -99,10 +95,11 @@ int main(void)
*/ */
while (1) { while (1) {
gpio_toggle(GPIOC, GPIO3); gpio_toggle(GPIOC, GPIO3);
printf("Hello World! %i %f %f\r\n", counter, fcounter, dcounter); printf("Hello World! %i %f %f\r\n", counter, fcounter,
dcounter);
counter++; counter++;
fcounter+=0.01; fcounter += 0.01;
dcounter+=0.01; dcounter += 0.01;
} }
return 0; return 0;

View File

@ -37,8 +37,7 @@ void gpio_setup(void)
/* Set GPIO12 (in GPIO port D) to 'output push-pull'. */ /* Set GPIO12 (in GPIO port D) to 'output push-pull'. */
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT,
GPIO_PUPD_NONE, GPIO_PUPD_NONE, GPIO12 | GPIO13 | GPIO14 | GPIO15);
GPIO12 | GPIO13 | GPIO14 | GPIO15);
} }
void button_setup(void) void button_setup(void)
@ -47,9 +46,7 @@ void button_setup(void)
rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN); rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN);
/* Set GPIO0 (in GPIO port A) to 'input open-drain'. */ /* Set GPIO0 (in GPIO port A) to 'input open-drain'. */
gpio_mode_setup(GPIOA, GPIO_MODE_INPUT, gpio_mode_setup(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO0);
GPIO_PUPD_NONE,
GPIO0);
} }
int main(void) int main(void)

View File

@ -35,8 +35,7 @@ void gpio_setup(void)
{ {
/* Set GPIO12-15 (in GPIO port D) to 'output push-pull'. */ /* Set GPIO12-15 (in GPIO port D) to 'output push-pull'. */
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT,
GPIO_PUPD_NONE, GPIO_PUPD_NONE, GPIO12 | GPIO13 | GPIO14 | GPIO15);
GPIO12 | GPIO13 | GPIO14 | GPIO15);
} }
int main(void) int main(void)

View File

@ -34,9 +34,7 @@ void gpio_setup(void)
// GPIOD_CRH = (GPIO_CNF_OUTPUT_PUSHPULL << (((8 - 8) * 4) + 2)); // GPIOD_CRH = (GPIO_CNF_OUTPUT_PUSHPULL << (((8 - 8) * 4) + 2));
// GPIOD_CRH |= (GPIO_MODE_OUTPUT_2_MHZ << ((8 - 8) * 4)); // GPIOD_CRH |= (GPIO_MODE_OUTPUT_2_MHZ << ((8 - 8) * 4));
/* Using API functions: */ /* Using API functions: */
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO12);
GPIO_PUPD_NONE,
GPIO12);
} }
int main(void) int main(void)

View File

@ -49,14 +49,10 @@ void usart_setup(void)
void gpio_setup(void) void gpio_setup(void)
{ {
/* Setup GPIO pin GPIO12 on GPIO port D for LED. */ /* Setup GPIO pin GPIO12 on GPIO port D for LED. */
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO12);
GPIO_PUPD_NONE,
GPIO12);
/* Setup GPIO pins for USART2 transmit. */ /* Setup GPIO pins for USART2 transmit. */
gpio_mode_setup(GPIOA, GPIO_MODE_AF, gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO2);
GPIO_PUPD_NONE,
GPIO2);
/* Setup USART2 TX pin as alternate function. */ /* Setup USART2 TX pin as alternate function. */
gpio_set_af(GPIOA, GPIO_AF7, GPIO2); gpio_set_af(GPIOA, GPIO_AF7, GPIO2);