This commit is contained in:
encrypt 2016-01-13 20:16:42 +01:00
parent a93b746839
commit a97d98549f

View file

@ -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) static int usbio_pwm_init(struct usb_device *usb_dev)
{ {
usbio_set_register_bit(usb_dev, ANSELD, 5, 0); int i, error = 0;
usbio_set_register_bit(usb_dev, TRISD, 5, 1); static const u8 register_bit_to_set[3][3] = {
usbio_set_register_bit(usb_dev, PSTR1CON, 1, 1); { ANSELD, 5, 0 },
usbio_set_register_bit(usb_dev, TRISD, 5, 0); { TRISD, 5, 1 },
usbio_set_register(usb_dev, CCPTMRS, 0x00); { PSTR1CON, 1, 1 }
usbio_set_register(usb_dev, PR2, 199); };
usbio_set_register(usb_dev, CCP1CON, 0b00001100); static const u8 register_to_set[5][2] = {
usbio_set_register(usb_dev, CCPR1L, 0x00); { CCPTMRS, 0x00 }, /* select timer resource */
usbio_set_register(usb_dev, T2CON, 0b00000110); { 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; return 0;
} }
@ -107,7 +126,7 @@ static int usbio_led_probe(struct usb_interface *interface, const struct usb_dev
} }
return 0; return 0;
error: error:
printk("errors"); printk("errors");
kfree(led); kfree(led);