PWM debug ready! (might reimpliment better, the macros suck)

This commit is contained in:
Brett Weiland 2023-11-04 01:42:06 -05:00
parent 1f74d8e77c
commit 4d61973a28

View File

@ -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;