diff options
| -rw-r--r-- | common/sleep_led.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/common/sleep_led.c b/common/sleep_led.c index edf68c352..dab3eb0f3 100644 --- a/common/sleep_led.c +++ b/common/sleep_led.c | |||
| @@ -45,29 +45,40 @@ void sleep_led_disable(void) | |||
| 45 | TIMSK1 &= ~_BV(OCIE1A); | 45 | TIMSK1 &= ~_BV(OCIE1A); |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | void sleep_led_toggle(void) | ||
| 49 | { | ||
| 50 | /* Disable Compare Match Interrupt */ | ||
| 51 | TIMSK1 ^= _BV(OCIE1A); | ||
| 52 | } | ||
| 53 | |||
| 48 | 54 | ||
| 49 | /* Breathing Sleep LED brighness(PWM On period) table | 55 | /* Breathing Sleep LED brighness(PWM On period) table |
| 50 | * (32[steps] * 8[duration]) / 64[PWM periods/s] = 4 second breath cycle | 56 | * (64[steps] * 4[duration]) / 64[PWM periods/s] = 4 second breath cycle |
| 57 | * | ||
| 58 | * http://www.wolframalpha.com/input/?i=%28sin%28+x%2F64*pi%29**8+*+255%2C+x%3D0+to+63 | ||
| 59 | * (0..63).each {|x| p ((sin(x/64.0*PI)**8)*255).to_i } | ||
| 51 | */ | 60 | */ |
| 52 | static const uint8_t breathing_table[32] PROGMEM = { | 61 | static const uint8_t breathing_table[64] PROGMEM = { |
| 53 | 0, 0, 0, 2, 9, 21, 37, 56, 78, 127, 151, 175, 197, 216, 232, 244, | 62 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 6, 10, |
| 54 | 254, 244, 216, 197, 175, 151, 127, 78, 56, 37, 21, 9, 2, 0, 0, 0 | 63 | 15, 23, 32, 44, 58, 74, 93, 113, 135, 157, 179, 199, 218, 233, 245, 252, |
| 64 | 255, 252, 245, 233, 218, 199, 179, 157, 135, 113, 93, 74, 58, 44, 32, 23, | ||
| 65 | 15, 10, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | ||
| 55 | }; | 66 | }; |
| 56 | 67 | ||
| 57 | ISR(TIMER1_COMPA_vect) | 68 | ISR(TIMER1_COMPA_vect) |
| 58 | { | 69 | { |
| 59 | /* Software PWM | 70 | /* Software PWM |
| 60 | * timer:1111 1111 1111 1111 | 71 | * timer:1111 1111 1111 1111 |
| 61 | * \----/\-/ \-------/+--- count(0-255) | 72 | * \_____/\/ \_______/____ count(0-255) |
| 62 | * | +--------------- duration of step(8) | 73 | * \ \______________ duration of step(4) |
| 63 | * +-------------------- index of step table(0-31) | 74 | * \__________________ index of step table(0-63) |
| 64 | */ | 75 | */ |
| 65 | static union { | 76 | static union { |
| 66 | uint16_t row; | 77 | uint16_t row; |
| 67 | struct { | 78 | struct { |
| 68 | uint8_t count:8; | 79 | uint8_t count:8; |
| 69 | uint8_t duration:3; | 80 | uint8_t duration:2; |
| 70 | uint8_t index:5; | 81 | uint8_t index:6; |
| 71 | } pwm; | 82 | } pwm; |
| 72 | } timer = { .row = 0 }; | 83 | } timer = { .row = 0 }; |
| 73 | 84 | ||
