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: unified_driver/led.cpp
- Revision:
- 9:84cb66d0375d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/unified_driver/led.cpp Thu Nov 06 02:22:01 2014 +0000 @@ -0,0 +1,53 @@ + +#include "unified_driver.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", + 1, + led_init, + led_read, + led_write, + led_fini, +};