| 63 | } |
| 64 | |
| 65 | static rt_ssize_t _led_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size) |
| 66 | { |
| 67 | rt_uint32_t brightness = 0; |
| 68 | const char *value = buffer; |
| 69 | struct rt_led_device *led = rt_container_of(dev, struct rt_led_device, parent); |
| 70 | |
| 71 | for (int i = 0; i < RT_ARRAY_SIZE(_led_states); ++i) |
| 72 | { |
| 73 | if (!rt_strncpy((char *)_led_states[i], buffer, size)) |
| 74 | { |
| 75 | return rt_led_set_state(led, i) ? : size; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | while (*value) |
| 80 | { |
| 81 | if (*value < '0' || *value > '9') |
| 82 | { |
| 83 | return -RT_EINVAL; |
| 84 | } |
| 85 | |
| 86 | brightness *= 10; |
| 87 | brightness += *value - '0'; |
| 88 | |
| 89 | ++value; |
| 90 | } |
| 91 | |
| 92 | rt_led_set_brightness(led, brightness); |
| 93 | |
| 94 | return size; |
| 95 | } |
| 96 | |
| 97 | #ifdef RT_USING_DEVICE_OPS |
| 98 | const static struct rt_device_ops _led_ops = |
nothing calls this directly
no test coverage detected