summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrett Weiland <brett_weiland@bpcspace.com>2023-10-27 08:17:36 -0500
committerBrett Weiland <brett_weiland@bpcspace.com>2023-10-27 08:17:36 -0500
commiteb86bdacd8b2908c7a4146aafd2b5696bd5cfafe (patch)
treef3203dbb8b6eb14b2041a69f5b16ae03fe6debe3
parent03a3acd11bce3ab11e225574ac6d3e0f93669056 (diff)
I will never be able to sleep before an exam
-rw-r--r--software_pwm.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/software_pwm.c b/software_pwm.c
index 73c40c8..2334976 100644
--- a/software_pwm.c
+++ b/software_pwm.c
@@ -27,15 +27,22 @@ static struct pwm_event {
#define LIST_INSERT(new, prev, member) (\
list_insert(&(new.member), &(prev.member), offsetof(struct pwm_event, member)))
-//TODO GYAAAAAAAGH!!!
+#define EVENT_FROM_MEMBER(member_ptr, member_offset) \
+ ((struct pwm_event *)(char *)member_ptr - member_offset)
+
+#define MEMBER_FROM_EVENT(event_ptr, member_offset) \
+ ((struct link_pair *)(char *)event_
+
static void list_insert(struct link_pair *new_links, struct link_pair *prev_links, size_t parent_offset) {
new_links->next = prev_links->next;
- new_links->prev = (struct pwm_event *)(char *)prev_links - parent_offset;
- ((struct link_pair *)(char *)prev_links->next + parent_offset)->prev = (struct pwm_event *)(char *)new_links - parent_offset; //GYAAAAGH
- prev_links->next = (struct pwm_event *)(char *)new_links - parent_offset;
+ new_links->prev = EVENT_FROM_MEMBER(prev_links, parent_offset);
+ ((struct link_pair *)(char *)prev_links->next + parent_offset)->prev =
+ EVENT_FROM_MEMBER(new_links, parent_offset); //GYAAAAGH
+ prev_links->next = EVENT_FROM_MEMBER(prev_links, parent_offset);
}
-static void list_remove(struct link_pair *event) {
+static void list_remove(struct link_pair *event_link, size_t parent_offset) {
+ event_link->prev
}
void init_softpwm() {
@@ -51,7 +58,8 @@ void init_softpwm() {
for(size_t event_i = 0; event_i < SOFTPWM_PIN_COUNT; event_i++) {
events[event_i].time = event_i;
events[event_i].pins = (1 << (event_i + 1)) - 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);
}
SOFTPWM_DDR = 0xff;
@@ -84,10 +92,8 @@ ISR(TIMER0_OVF_vect) {
**/
ISR(TIMER0_COMP_vect) {
- /**
static struct pwm_event *on_event = &events[SOFTPWM_PIN_COUNT];
SOFTPWM_PORT = on_event->pins;
on_event = on_event->next;
OCR0A = on_event->time;
- **/
}