summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--software_pwm.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/software_pwm.c b/software_pwm.c
index 1de0d37..5b55026 100644
--- a/software_pwm.c
+++ b/software_pwm.c
@@ -23,13 +23,14 @@ static struct pwm_event {
bool enabled;
} events[SOFTPWM_PIN_COUNT + 1];
+//these macros and the list_insert/remove functions are kinda ass.
//if list_insert and list_remove end up being too slow, these have a lot of room for
-//optimization. We could do a preprocessor IF/THEN instead of using member offset
-//TODO accept pointer instead of actual value
+//optimization. We could do a preprocessor IF/THEN instead of using member offset,
+//who knows, maybe even a inline funciton that can handle all the cases would be better.
#define LIST_INSERT(new, prev, member) (\
- list_insert(new->member, prev->member, offsetof(struct pwm_event, member)))
+ list_insert(&((new)->member), &((prev)->member), offsetof(struct pwm_event, member)))
-#define LIST_REMOVE(event, member) list_remove((event)->member, offsetof(struct pwm_event, member))
+#define LIST_REMOVE(event, member) list_remove(&((event)->member), offsetof(struct pwm_event, member))
#define EVENT_FROM_MEMBER(member_ptr, member_offset) \
((struct pwm_event *)(char *)member_ptr - member_offset)
@@ -64,8 +65,8 @@ void init_softpwm() {
for(size_t event_i = 1; event_i <= SOFTPWM_PIN_COUNT; event_i++) {
events[event_i].time = event_i;
events[event_i].pins = (1 << event_i) - 1;
- LIST_INSERT(&(events[event_i]),
- &events[((int)event_i - 1) % (SOFTPWM_PIN_COUNT + 1)], active);
+ LIST_INSERT(&events[event_i],
+ &(events[((int)event_i - 1) % (SOFTPWM_PIN_COUNT + 1)]), active);
events[event_i].enabled = true;
}
@@ -124,11 +125,6 @@ void softpwm_set(uint8_t pin, uint8_t duty) {
pin_event->time = duty;
}
-/**
-ISR(TIMER0_OVF_vect) {
-}
-**/
-
ISR(TIMER0_COMP_vect) {
static struct pwm_event *on_event = &events[SOFTPWM_PIN_COUNT];
SOFTPWM_PORT = on_event->pins;