Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API color_pixels mbed-src-nrf51822 nRF51822
Fork of BLE_LoopbackUART by
Diff: udriver/led.cpp
- Revision:
- 10:f34ff4e47741
- Parent:
- 9:84cb66d0375d
- Child:
- 11:c0885b74a63a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/udriver/led.cpp Thu Jun 04 09:34:13 2015 +0000 @@ -0,0 +1,53 @@ + +#include "udriver.h" +#include "mbed.h" + +int led_init(void *obj, void *params) +{ + int pin = *(int *)params; + *((PwmOut **)obj) = new PwmOut((PinName)pin); + + return 0; +} + + +int led_read(void *obj, void *data) +{ + PwmOut *output = *(PwmOut **)obj; + + *(float *)data = output->read(); + + return 0; +} + +int led_write(void *obj, void *data) +{ + PwmOut *pwm = *(PwmOut **)obj; + float pulse_width = *(float *)data; + float period = *((float *)data + 1); + + pwm->write(pulse_width); + if (0 != period) { + pwm->period(period); + } + + return 0; +} + +int led_fini(void *obj) +{ + PwmOut *ptr = *(PwmOut **)obj; + delete ptr; + + return 0; +} + +driver_t led_driver = +{ + led_init, + led_read, + led_write, + led_fini, + + 2, +};