other/*: Random coding-style fixes.

This commit is contained in:
Uwe Hermann 2011-11-13 09:13:27 +01:00
parent 8a77630997
commit 7f1e75c3a8
6 changed files with 101 additions and 94 deletions

View File

@ -73,7 +73,7 @@ void rtc_isr(void)
volatile u32 j = 0, c = 0;
/* The interrupt flag isn't cleared by hardware, we have to do it. */
rtc_clear_flag(RTC_SEC);
rtc_clear_flag(RTC_SEC);
/* Visual output. */
gpio_toggle(GPIOC, GPIO12);
@ -110,7 +110,7 @@ int main(void)
/* Enable the RTC interrupt to occur off the SEC flag. */
rtc_interrupt_enable(RTC_SEC);
while(1);
while (1);
return 0;
}

View File

@ -37,11 +37,11 @@ void gpio_setup(void)
GPIO_CNF_OUTPUT_PUSHPULL, GPIO7);
}
void sys_tick_handler()
void sys_tick_handler(void)
{
temp32++;
/* we call this handler every 1ms so 1000ms = 1s on/off */
/* We call this handler every 1ms so 1000ms = 1s on/off. */
if (temp32 == 1000) {
gpio_toggle(GPIOB, GPIO6); /* LED2 on/off */
temp32 = 0;
@ -50,26 +50,26 @@ void sys_tick_handler()
int main(void)
{
rcc_clock_setup_in_hse_16mhz_out_72mhz();
rcc_clock_setup_in_hse_16mhz_out_72mhz();
gpio_setup();
gpio_clear(GPIOB, GPIO7); /* LED1 on */
gpio_set(GPIOB, GPIO6); /* LED2 off */
temp32 = 0;
/* 72MHz / 8 => 9000000 counts per second */
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
/* 9000000/9000 = 1000 overflows per second - every 1ms one interrupt */
systick_set_reload(9000);
systick_interrupt_enable();
/* start counting */
/* Start counting. */
systick_counter_enable();
while(1); /* Halt. */
while (1); /* Halt. */
return 0;
}

View File

@ -35,51 +35,51 @@ void gpio_setup(void)
GPIO_CNF_OUTPUT_PUSHPULL, GPIO7);
}
void nvic_setup()
void nvic_setup(void)
{
/* without this the timer interrupt routine will never be called */
/* Without this the timer interrupt routine will never be called. */
nvic_enable_irq(NVIC_TIM2_IRQ);
nvic_set_priority(NVIC_TIM2_IRQ, 1);
nvic_set_priority(NVIC_TIM2_IRQ, 1);
}
void tim2_isr()
void tim2_isr(void)
{
/* LED2 on/off */
gpio_toggle(GPIOB, GPIO6);
/* clear interrrupt flag */
TIM_SR(TIM2) &= ~TIM_SR_UIF;
gpio_toggle(GPIOB, GPIO6); /* LED2 on/off. */
TIM_SR(TIM2) &= ~TIM_SR_UIF; /* Clear interrrupt flag. */
}
int main(void)
{
rcc_clock_setup_in_hse_16mhz_out_72mhz();
rcc_clock_setup_in_hse_16mhz_out_72mhz();
gpio_setup();
nvic_setup();
gpio_clear(GPIOB, GPIO7); /* LED1 on */
gpio_set(GPIOB, GPIO6); /* LED2 off */
rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_TIM2EN);
/* the goal is to let the LED2 glow for a second and then be off for a second */
/*
* The goal is to let the LED2 glow for a second and then be
* off for a second.
*/
/* Set timer start value */
/* Set timer start value. */
TIM_CNT(TIM2) = 1;
/* Set timer prescaler. 72MHz/1440 => 50000 counts per second */
/* Set timer prescaler. 72MHz/1440 => 50000 counts per second. */
TIM_PSC(TIM2) = 1440;
/* End timer value. If this value is reached an interrupt is generated */
/* End timer value. If this is reached an interrupt is generated. */
TIM_ARR(TIM2) = 50000;
/* Update interrupt enable */
/* Update interrupt enable. */
TIM_DIER(TIM2) |= TIM_DIER_UIE;
/* Start timer */
/* Start timer. */
TIM_CR1(TIM2) |= TIM_CR1_CEN;
while(1); /* Halt. */
while (1); /* Halt. */
return 0;
}

View File

@ -24,25 +24,27 @@
#include <libopencm3/usb/cdc.h>
static const struct usb_device_descriptor dev = {
.bLength = USB_DT_DEVICE_SIZE,
.bDescriptorType = USB_DT_DEVICE,
.bcdUSB = 0x0200,
.bDeviceClass = USB_CLASS_CDC,
.bDeviceSubClass = 0,
.bDeviceProtocol = 0,
.bMaxPacketSize0 = 64,
.idVendor = 0x0483,
.idProduct = 0x5740,
.bcdDevice = 0x0200,
.iManufacturer = 1,
.iProduct = 2,
.iSerialNumber = 3,
.bNumConfigurations = 1,
.bLength = USB_DT_DEVICE_SIZE,
.bDescriptorType = USB_DT_DEVICE,
.bcdUSB = 0x0200,
.bDeviceClass = USB_CLASS_CDC,
.bDeviceSubClass = 0,
.bDeviceProtocol = 0,
.bMaxPacketSize0 = 64,
.idVendor = 0x0483,
.idProduct = 0x5740,
.bcdDevice = 0x0200,
.iManufacturer = 1,
.iProduct = 2,
.iSerialNumber = 3,
.bNumConfigurations = 1,
};
/* This notification endpoint isn't implemented. According to CDC spec its
* optional, but its absence causes a NULL pointer dereference in Linux cdc_acm
* driver. */
/*
* This notification endpoint isn't implemented. According to CDC spec its
* optional, but its absence causes a NULL pointer dereference in Linux
* cdc_acm driver.
*/
static const struct usb_endpoint_descriptor comm_endp[] = {{
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
@ -159,7 +161,7 @@ static const char *usb_strings[] = {
"x",
"Black Sphere Technologies",
"CDC-ACM Demo",
"DEMO"
"DEMO",
};
static int cdcacm_control_request(struct usb_setup_data *req, u8 **buf,
@ -170,13 +172,15 @@ static int cdcacm_control_request(struct usb_setup_data *req, u8 **buf,
switch(req->bRequest) {
case USB_CDC_REQ_SET_CONTROL_LINE_STATE: {
/* This Linux cdc_acm driver requires this to be implemented
* even though it's optional in the CDC spec, and we don't
* advertise it in the ACM functional descriptor. */
/*
* This Linux cdc_acm driver requires this to be implemented
* even though it's optional in the CDC spec, and we don't
* advertise it in the ACM functional descriptor.
*/
char buf[10];
struct usb_cdc_notification *notif = (void*)buf;
struct usb_cdc_notification *notif = (void *)buf;
/* We echo signals back to host as notification */
/* We echo signals back to host as notification. */
notif->bmRequestType = 0xA1;
notif->bNotification = USB_CDC_NOTIFY_SERIAL_STATE;
notif->wValue = 0;
@ -184,11 +188,11 @@ static int cdcacm_control_request(struct usb_setup_data *req, u8 **buf,
notif->wLength = 2;
buf[8] = req->wValue & 3;
buf[9] = 0;
//usbd_ep_write_packet(0x83, buf, 10);
// usbd_ep_write_packet(0x83, buf, 10);
return 1;
}
case USB_CDC_REQ_SET_LINE_CODING:
if(*len < sizeof(struct usb_cdc_line_coding))
if(*len < sizeof(struct usb_cdc_line_coding))
return 0;
return 1;
@ -202,7 +206,8 @@ static void cdcacm_data_rx_cb(u8 ep)
char buf[64];
int len = usbd_ep_read_packet(0x01, buf, 64);
if(len) {
if (len) {
usbd_ep_write_packet(0x82, buf, len);
buf[len] = 0;
}
@ -217,14 +222,14 @@ static void cdcacm_set_config(u16 wValue)
usbd_ep_setup(0x83, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
usbd_register_control_callback(
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
cdcacm_control_request);
}
int main(void)
{
rcc_clock_setup_in_hsi_out_48mhz();
rcc_clock_setup_in_hsi_out_48mhz();
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
@ -237,9 +242,9 @@ int main(void)
usbd_register_set_config_callback(cdcacm_set_config);
gpio_set(GPIOA, GPIO15);
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
while (1)
while (1)
usbd_poll();
}

View File

@ -111,7 +111,7 @@ static const char *usb_strings[] = {
"DFU Demo",
"DEMO",
/* This string is used by ST Microelectronics' DfuSe utility. */
"@Internal Flash /0x08000000/8*001Ka,56*001Kg"
"@Internal Flash /0x08000000/8*001Ka,56*001Kg",
};
static u8 usbdfu_getstatus(u32 *bwPollTimeout)

View File

@ -33,23 +33,23 @@
#endif
const struct usb_device_descriptor dev = {
.bLength = USB_DT_DEVICE_SIZE,
.bDescriptorType = USB_DT_DEVICE,
.bcdUSB = 0x0200,
.bDeviceClass = 0,
.bDeviceSubClass = 0,
.bDeviceProtocol = 0,
.bMaxPacketSize0 = 64,
.idVendor = 0x0483,
.idProduct = 0x5710,
.bcdDevice = 0x0200,
.iManufacturer = 1,
.iProduct = 2,
.iSerialNumber = 3,
.bNumConfigurations = 1,
.bLength = USB_DT_DEVICE_SIZE,
.bDescriptorType = USB_DT_DEVICE,
.bcdUSB = 0x0200,
.bDeviceClass = 0,
.bDeviceSubClass = 0,
.bDeviceProtocol = 0,
.bMaxPacketSize0 = 64,
.idVendor = 0x0483,
.idProduct = 0x5710,
.bcdDevice = 0x0200,
.iManufacturer = 1,
.iProduct = 2,
.iSerialNumber = 3,
.bNumConfigurations = 1,
};
/* I have no idea what this means. I haven't read the HID spec. */
/* I have no idea what this means. I haven't read the HID spec. */
static const u8 hid_report_descriptor[] = {
0x05, 0x01, 0x09, 0x02, 0xA1, 0x01, 0x09, 0x01,
0xA1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x03,
@ -60,7 +60,7 @@ static const u8 hid_report_descriptor[] = {
0x81, 0x06, 0xC0, 0x09, 0x3c, 0x05, 0xff, 0x09,
0x01, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95,
0x02, 0xb1, 0x22, 0x75, 0x06, 0x95, 0x01, 0xb1,
0x01, 0xc0
0x01, 0xc0,
};
static const struct {
@ -174,13 +174,13 @@ static int hid_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
{
(void)complete;
if((req->bmRequestType != 0x81) ||
if((req->bmRequestType != 0x81) ||
(req->bRequest != USB_REQ_GET_DESCRIPTOR) ||
(req->wValue != 0x2200))
return 0;
(req->wValue != 0x2200))
return 0;
/* Handle the HID report descriptor */
*buf = (u8*)hid_report_descriptor;
/* Handle the HID report descriptor. */
*buf = (u8 *)hid_report_descriptor;
*len = sizeof(hid_report_descriptor);
return 1;
@ -192,8 +192,8 @@ static void dfu_detach_complete(struct usb_setup_data *req)
(void)req;
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO10);
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO10);
gpio_set(GPIOA, GPIO10);
scb_reset_core();
}
@ -201,11 +201,11 @@ static void dfu_detach_complete(struct usb_setup_data *req)
static int dfu_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
void (**complete)(struct usb_setup_data *req))
{
(void)buf;
(void)buf;
(void)len;
if((req->bmRequestType != 0x21) || (req->bRequest != DFU_DETACH))
return 0; /* Only accept class request */
if ((req->bmRequestType != 0x21) || (req->bRequest != DFU_DETACH))
return 0; /* Only accept class request. */
*complete = dfu_detach_complete;
@ -230,7 +230,7 @@ static void hid_set_config(u16 wValue)
dfu_control_request);
#endif
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
systick_set_reload(100000);
systick_interrupt_enable();
systick_counter_enable();
@ -238,7 +238,7 @@ static void hid_set_config(u16 wValue)
int main(void)
{
rcc_clock_setup_in_hsi_out_48mhz();
rcc_clock_setup_in_hsi_out_48mhz();
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
@ -250,10 +250,10 @@ int main(void)
usbd_register_set_config_callback(hid_set_config);
gpio_set(GPIOA, GPIO15);
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
while (1)
while (1)
usbd_poll();
}
@ -265,8 +265,10 @@ void sys_tick_handler(void)
buf[1] = dir;
x += dir;
if(x > 30) dir = -dir;
if(x < -30) dir = -dir;
if (x > 30)
dir = -dir;
if (x < -30)
dir = -dir;
usbd_ep_write_packet(0x81, buf, 4);
}