From a97d98549f72b6cdb958e91a393823409e3a9a34 Mon Sep 17 00:00:00 2001 From: encrypt Date: Wed, 13 Jan 2016 20:16:42 +0100 Subject: [PATCH] restyle --- led/usbio-led.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/led/usbio-led.c b/led/usbio-led.c index 17b6c4b..8021bac 100644 --- a/led/usbio-led.c +++ b/led/usbio-led.c @@ -56,15 +56,34 @@ int usbio_set_register_bit(struct usb_device *usb_dev, u8 reg, u8 reg_bit, u8 va static int usbio_pwm_init(struct usb_device *usb_dev) { - usbio_set_register_bit(usb_dev, ANSELD, 5, 0); - usbio_set_register_bit(usb_dev, TRISD, 5, 1); - usbio_set_register_bit(usb_dev, PSTR1CON, 1, 1); - usbio_set_register_bit(usb_dev, TRISD, 5, 0); - usbio_set_register(usb_dev, CCPTMRS, 0x00); - usbio_set_register(usb_dev, PR2, 199); - usbio_set_register(usb_dev, CCP1CON, 0b00001100); - usbio_set_register(usb_dev, CCPR1L, 0x00); - usbio_set_register(usb_dev, T2CON, 0b00000110); + int i, error = 0; + static const u8 register_bit_to_set[3][3] = { + { ANSELD, 5, 0 }, + { TRISD, 5, 1 }, + { PSTR1CON, 1, 1 } + }; + static const u8 register_to_set[5][2] = { + { CCPTMRS, 0x00 }, /* select timer resource */ + { PR2, 199 }, /* load width PWM period value */ + { CCP1CON, 0b00001100 }, /* enable pwm mode bit(3-0), bit(5-4) LSB PWM duty cycle */ + { CCPR1L, 0x00 }, + { T2CON, 0b00000110 } + }; + for(i = 0; i < 3; i++) { + error = usbio_set_register_bit(usb_dev, + register_bit_to_set[i][0], + register_bit_to_set[i][1], + register_bit_to_set[i][2]); + if(error < 0) + return error; + } + for(i = 0; i < 5; i++) { + error = usbio_set_register(usb_dev, + register_to_set[i][0], + register_to_set[i][1]); + if(error < 0) + return error; + } return 0; } @@ -107,7 +126,7 @@ static int usbio_led_probe(struct usb_interface *interface, const struct usb_dev } return 0; - + error: printk("errors"); kfree(led);