Skip to content

Commit

Permalink
Rudimentary pulse train streaming.
Browse files Browse the repository at this point in the history
  • Loading branch information
Onwrikbaar committed Dec 29, 2024
1 parent 510672e commit 7f8c97a
Show file tree
Hide file tree
Showing 14 changed files with 1,628 additions and 1,579 deletions.
2,973 changes: 1,494 additions & 1,479 deletions firmware/build/neodk_g071.hex

Large diffs are not rendered by default.

8 changes: 1 addition & 7 deletions firmware/inc/bsp_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@

#include "convenience.h"
#include "eventqueue.h"

typedef struct {
uint8_t elcon[2];
uint8_t pulse_width_micros;
uint8_t pace_ms;
uint8_t nr_of_pulses;
} Burst;
#include "burst.h"


void BSP_init(void); // Get the hardware ready for action.
Expand Down
26 changes: 26 additions & 0 deletions firmware/inc/burst.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* burst.h
*
* NOTICE (do not remove):
* This file is part of project NeoDK (https://github.com/Onwrikbaar/NeoDK).
* See https://github.com/Onwrikbaar/NeoDK/blob/main/LICENSE.txt for full license details.
*
* Created on: 29 Dec 2024
* Author: mark
* Copyright 2024, 2025 Neostim™
*/

#ifndef INC_BURST_H_
#define INC_BURST_H_

#include <stdint.h>

typedef struct {
uint8_t elcon[2];
uint8_t phase;
uint8_t pace_ms;
uint16_t nr_of_pulses;
uint8_t pulse_width_micros;
} Burst;

#endif
4 changes: 2 additions & 2 deletions firmware/inc/datalink.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* Created on: 24 Feb 2024
* Author: mark
* Copyright 2024 Neostim™
* Copyright 2024, 2025 Neostim™
*/

#ifndef INC_DATALINK_H_
Expand All @@ -25,7 +25,7 @@ DataLink *DataLink_new();

// Instance methods.
bool DataLink_open(DataLink *, EventQueue *);
void DataLink_waitForSync(DataLink *);
void DataLink_awaitSync(DataLink *);
bool DataLink_sendDebugPacket(DataLink *, uint8_t const *, uint16_t);
bool DataLink_sendDatagram(DataLink *, uint8_t const *, uint16_t);
void DataLink_close(DataLink *);
Expand Down
29 changes: 14 additions & 15 deletions firmware/inc/pulse_train.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,25 @@
* Copyright 2019..2025 Neostim™
*/

#ifndef INC_BURST_H_
#define INC_BURST_H_
#ifndef INC_PULSE_TRAIN_H_
#define INC_PULSE_TRAIN_H_

#include <stdint.h>
#include "burst.h"

typedef struct _PulseTrain PulseTrain; // Opaque type.
typedef uint8_t burst_size_t;
typedef uint8_t burst_phase_t;
typedef struct _PulseTrain PulseTrain; // Opaque type.
typedef uint8_t pulse_train_size_t;

// Class methods.
burst_size_t PulseTrain_size();
PulseTrain *PulseTrain_new(void *addr, burst_size_t);
PulseTrain *PulseTrain_copy(void *addr, burst_size_t, PulseTrain const *original);
pulse_train_size_t PulseTrain_size();
PulseTrain *PulseTrain_new(void *addr, pulse_train_size_t);
PulseTrain *PulseTrain_copy(void *addr, pulse_train_size_t, PulseTrain const *original);

// Instance methods.
PulseTrain *PulseTrain_init(PulseTrain *, uint8_t electrode_set[2], uint16_t nr_of_pulses);
void PulseTrain_setPhase(PulseTrain *, burst_phase_t phase);
burst_phase_t PulseTrain_phase(PulseTrain const *);
PulseTrain *PulseTrain_setStartTimeMicros(PulseTrain *, uint32_t start_time_micros);
uint16_t PulseTrain_nrOfPulses(PulseTrain const *);
void PulseTrain_print(PulseTrain const *);
PulseTrain *PulseTrain_init(PulseTrain *, uint8_t electrode_set[2], uint16_t nr_of_pulses);
PulseTrain *PulseTrain_setStartTimeMicros(PulseTrain *, uint32_t start_time_micros);
uint16_t PulseTrain_amplitude(PulseTrain const *);
uint8_t PulseTrain_pulseWidth(PulseTrain const *);
Burst const *PulseTrain_getBurst(PulseTrain const *, Burst *);
void PulseTrain_print(PulseTrain const *);

#endif
Binary file modified firmware/maolib/libmao.a
Binary file not shown.
12 changes: 6 additions & 6 deletions firmware/src/attributes.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* Created on: 15 Oct 2024
* Author: mark
* Copyright 2024 Neostim™
* Copyright 2024, 2025 Neostim™
*/

#include "bsp_dbg.h"
Expand All @@ -19,7 +19,7 @@

typedef struct {
AttributeId ai; // Key.
uint16_t active;
uint16_t times;
AttrNotifier notify;
void *target;
} Subscription;
Expand All @@ -40,7 +40,7 @@ static Subscription *findSubForId(AttributeId ai)
}


static SubscriptionId setSubForId(AttributeId ai, AttrNotifier notify, void *target, uint16_t count)
static SubscriptionId setSubForId(AttributeId ai, AttrNotifier notify, void *target, uint16_t times)
{
Subscription *sub = findSubForId(ai);
if (sub == NULL) { // Not present, add it if there is room.
Expand All @@ -50,7 +50,7 @@ static SubscriptionId setSubForId(AttributeId ai, AttrNotifier notify, void *tar
}
sub->notify = notify;
sub->target = target;
sub->active = count;
sub->times = times;
return 256 + (sub - subscriptions);
}

Expand All @@ -76,8 +76,8 @@ void Attribute_changed(AttributeId ai, ElementEncoding enc, uint8_t const *data,
{
// BSP_logf("%s(%hu)\n", __func__, ai);
Subscription *sub = findSubForId(ai);
if (sub != NULL && sub->active) {
if (sub != NULL && sub->times != 0) {
sub->notify(sub->target, ai, enc, data, size);
sub->active -= 1;
sub->times -= 1;
}
}
14 changes: 3 additions & 11 deletions firmware/src/bsp_stm32g071.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,6 @@ static void setPinVal(GPIO_TypeDef *GPIOx, uint16_t gpio_pin, uint8_t pin_state)
}


static uint8_t getPhase(uint8_t const elcon[2])
{
M_ASSERT((elcon[0] & elcon[1]) == 0); // Prevent shorts.
return (elcon[0] & 0x5) ? 0 : 1;
}


static void setSwitches(uint16_t pattern)
{
// Turn on the LED if at least one triac will be activated.
Expand Down Expand Up @@ -645,7 +638,7 @@ void BSP_init()

char const *BSP_firmwareVersion()
{
return "v0.42-beta";
return "v0.43-beta";
}


Expand Down Expand Up @@ -842,11 +835,10 @@ bool BSP_startBurst(Burst const *burst)
pulse_timer->RCR = burst->nr_of_pulses - 1;
pulse_timer->CNT = 0;
pulse_timer->SR &= ~(TIM_SR_CC1IF | TIM_SR_CC2IF);
uint8_t phase = getPhase(burst->elcon);
if (phase == 0) {
if (burst->phase == 0) {
pulse_timer->CCR1 = burst->pulse_width_micros - 1;
pulse_timer->DIER |= TIM_DIER_CC1IE;
} else if (phase == 1) {
} else if (burst->phase == 1) {
pulse_timer->CCR2 = burst->pulse_width_micros - 1;
pulse_timer->DIER |= TIM_DIER_CC2IE;
} else return false; // We only have one output stage.
Expand Down
11 changes: 2 additions & 9 deletions firmware/src/controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,6 @@ static void handleWriteRequest(Controller *me, AttributeAction const *aa)
}


static void handleSubscribeRequest(Controller *me, AttributeAction const *aa)
{
Attribute_subscribe(aa->attribute_id, (AttrNotifier)&attributeChanged, me);
// Do not send a status response here. It will be sent later.
}


static void handleInvokeRequest(Controller *me, AttributeAction const *aa)
{
switch (aa->attribute_id)
Expand Down Expand Up @@ -253,7 +246,7 @@ static void handleRequest(Controller *me, AttributeAction const *aa)
break;
case OC_SUBSCRIBE_REQUEST:
logTransaction(aa, "subscribe to");
handleSubscribeRequest(me, aa);
Attribute_subscribe(aa->attribute_id, (AttrNotifier)&attributeChanged, me);
handleReadRequest(me, aa);
break;
case OC_INVOKE_REQUEST:
Expand Down Expand Up @@ -338,7 +331,7 @@ void Controller_start(Controller *me)
me->state = &stateIdle;
me->state(me, AOEvent_newEntryEvent());
DataLink_open(me->datalink, &me->event_queue);
DataLink_waitForSync(me->datalink);
DataLink_awaitSync(me->datalink);
BSP_logf("Starting NeoDK!\n%s", welcome_msg);
}

Expand Down
14 changes: 2 additions & 12 deletions firmware/src/datalink.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* Created on: 24 Feb 2024
* Author: mark
* Copyright 2024 Neostim™
* Copyright 2024, 2025 Neostim™
*/

#include <stdlib.h>
Expand Down Expand Up @@ -50,15 +50,6 @@ static void init(DataLink *me)
me->tx_seq_nr = 0;
}

__attribute__((unused))
static void dumpBuffer(const char *prefix, const uint8_t *bbuf, uint8_t nb)
{
if (prefix != NULL) BSP_logf("%s", prefix);
for (uint8_t i = 0; i < nb; i++) {
BSP_logf(" 0x%02x", bbuf[i]);
}
}


static void makeRoomForNextByte(DataLink *me)
{
Expand Down Expand Up @@ -283,9 +274,8 @@ bool DataLink_open(DataLink *me, EventQueue *dq)
}


void DataLink_waitForSync(DataLink *me)
void DataLink_awaitSync(DataLink *me)
{
BSP_logf("%s\n", __func__);
me->synced = false;
}

Expand Down
9 changes: 6 additions & 3 deletions firmware/src/debug_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* Created on: 26 Mar 2024
* Author: mark
* Copyright 2024 Neostim™
* Copyright 2024, 2025 Neostim™
*/

#include <stdio.h>
Expand Down Expand Up @@ -66,7 +66,7 @@ static void interpretCommand(CmndInterp *me, char ch)
switch (ch)
{
case '?':
CLI_logf("Commands: /? /a /b /d /l /n /q /u /v /w /0 /1../9\n");
CLI_logf("Commands: /? /a /b /d /l /n /q /s /u /v /w /0 /1../9\n");
break;
case '0':
BSP_primaryVoltageEnable(false);
Expand Down Expand Up @@ -97,14 +97,17 @@ static void interpretCommand(CmndInterp *me, char ch)
EventQueue_postEvent(me->delegate, ET_POSIX_SIGNAL, (uint8_t const *)&sig, sizeof sig);
break;
}
case 's':
EventQueue_postEvent((EventQueue *)me->sequencer, ET_STOP, NULL, 0);
break;
case 'u': // Intensity up.
changeIntensity(me, +2);
break;
case 'v':
CLI_logf("Firmware %s\n", BSP_firmwareVersion());
break;
case 'w': // Allow rediscovery by Dweeb.
DataLink_waitForSync(me->datalink);
DataLink_awaitSync(me->datalink);
break;
default:
CLI_logf("Unknown command '/%c'\n", ch);
Expand Down
2 changes: 1 addition & 1 deletion firmware/src/pattern_iter.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static void nextElconIfLastStep(PatternIterator *me)
}


static uint8_t const *getNextPattern(PatternIterator *me, uint8_t *nr_of_pulses)
static uint8_t const *getNextPattern(PatternIterator *me, uint16_t *nr_of_pulses)
{
PatternDescr const *pd = me->pattern_descr;
uint8_t elcon_nr = me->elcon_nr;
Expand Down
Loading

0 comments on commit 7f8c97a

Please sign in to comment.