Skip to content

Commit

Permalink
fixing example compiling, Lint checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
MX682X committed Sep 27, 2024
1 parent 9f88fc5 commit d07ec31
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 97 deletions.
9 changes: 8 additions & 1 deletion megaavr/libraries/PTC/examples/mutualcap/mutualcap.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* otherwise the handling of the successive nodes would be delayed.
*/
#define MySerial Serial

#if !defined(MILLIS_USE_TIMERNONE)
cap_sensor_t nodes[2];

void setup() {
Expand Down Expand Up @@ -58,3 +58,10 @@ void ptc_event_cb_calibration(const ptc_cb_event_t eventType, cap_sensor_t *node
MySerial.print(" Node: ");
MySerial.println(ptc_get_node_id(node));
}
#else
void setup() {
}
void loop () {
}
#endif

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* PA4 is the X-Line, while PA5, PA6 and PA7 act as Y-Line.
*/
#define MySerial Serial

#if !defined(MILLIS_USE_TIMERNONE)
cap_sensor_t nodes[3];
cap_sensor_t lp_node; // as an example, could also be part of the array above

Expand Down Expand Up @@ -91,10 +91,17 @@ void ptc_event_cb_calibration(const ptc_cb_event_t eventType, cap_sensor_t *node
}

void ptc_event_cb_wake(const ptc_cb_event_t eventType, cap_sensor_t *node) {
if (PTC_CB_EVENT_WAKE_TOUCH == eventType) {
// True if the node was touched when a wakeup occurred
if (PTC_CB_EVENT_WAKE_TOUCH == eventType) {
// True if the node was touched when a wakeup occurred
} else if (PTC_CB_EVENT_WAKE_NO_TOUCH == eventType) {
// True if the node was no touch when a wakeup occurred
}
(void)node; // remove unused warning
}
#else
void setup() {
}
void loop () {
}
#endif

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


#define MySerial Serial
#if !defined(MILLIS_USE_TIMERNONE)
cap_sensor_t nodes[4];


Expand Down Expand Up @@ -65,3 +66,10 @@ void ptc_event_cb_calibration(const ptc_cb_event_t eventType, cap_sensor_t *node
MySerial.print(" Node: ");
MySerial.println(ptc_get_node_id(node));
}
#else
void setup() {
}
void loop () {
}
#endif

8 changes: 7 additions & 1 deletion megaavr/libraries/PTC/examples/selfcap/selfcap.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* otherwise the handling of the successive nodes would be delayed.
*/
#define MySerial Serial

#if !defined(MILLIS_USE_TIMERNONE)
cap_sensor_t nodes[3];

void setup() {
Expand Down Expand Up @@ -60,3 +60,9 @@ void ptc_event_cb_calibration(const ptc_cb_event_t eventType, cap_sensor_t *node
MySerial.print(" Node: ");
MySerial.println(ptc_get_node_id(node));
}
#else
void setup() {
}
void loop () {
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* as shield. This improves the signal-to-noise ratio.
*/
#define MySerial Serial

#if !defined(MILLIS_USE_TIMERNONE)
cap_sensor_t nodes[3];

void setup() {
Expand Down Expand Up @@ -54,3 +54,10 @@ void ptc_event_callback(const ptc_cb_event_t eventType, cap_sensor_t *node) {
MySerial.println(ptc_get_node_id(node));
}
}
#else
void setup() {
}
void loop () {
}
#endif

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* as shield. This improves the signal-to-noise ratio.
*/
#define MySerial Serial

#if !defined(MILLIS_USE_TIMERNONE)
cap_sensor_t nodes[2];

void setup() {
Expand Down Expand Up @@ -59,3 +59,10 @@ void ptc_event_cb_calibration(const ptc_cb_event_t eventType, cap_sensor_t *node
MySerial.print(" Node: ");
MySerial.println(ptc_get_node_id(node));
}
#else
void setup() {
}
void loop () {
}
#endif

81 changes: 41 additions & 40 deletions megaavr/libraries/PTC/src/ptc.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Refer to ptc.h file for copyright, changelog, usage and license information
*/

Expand All @@ -9,30 +9,30 @@

// The following functions are used internally only.
// get the pointer of the last valid node struct can be "firstNode"
cap_sensor_t* ptc_get_last_node(void);
cap_sensor_t *ptc_get_last_node(void);


uint8_t ptc_append_node(cap_sensor_t* pNewNode);
uint8_t ptc_append_node(cap_sensor_t *pNewNode);

// Prepares the ADC/PTC registers for the next conversion batch, starts conversion with firstNode
void ptc_init_conversion(uint8_t nodeType);

// Starts the conversion of the node that is passed as argument
void ptc_start_conversion (cap_sensor_t* node);
void ptc_start_conversion (cap_sensor_t *node);

// State-Machine Handler, interprets the measured values and decides if key is "pressed"
void ptc_process_node_sm (cap_sensor_t* node);
void ptc_process_node_sm (cap_sensor_t *node);

// Helper function
void ptc_process_measurement (cap_sensor_t* node);
void ptc_process_measurement (cap_sensor_t *node);

// Handles (initial) calibration
uint8_t ptc_process_calibrate (cap_sensor_t* node);
uint8_t ptc_process_calibrate (cap_sensor_t *node);

// Handles adjustment of the reference value when a button is not pressed
void ptc_process_adjust ();

void ptc_set_registers(cap_sensor_t* node);
void ptc_set_registers(cap_sensor_t *node);


cap_sensor_t *firstNode = NULL;
Expand Down Expand Up @@ -65,7 +65,7 @@ ptc_lib_sm_set_t ptc_sm_settings = {
.drift_down_nom = 15
};

ptc_lib_sm_set_t* ptc_get_sm_settings() {
ptc_lib_sm_set_t *ptc_get_sm_settings() {
return &ptc_sm_settings;
}

Expand All @@ -91,15 +91,15 @@ ptc_lib_sm_set_t* ptc_get_sm_settings() {


__attribute__ ((weak))
void ptc_event_callback(const ptc_cb_event_t eventType, cap_sensor_t* node) {
void ptc_event_callback(const ptc_cb_event_t eventType, cap_sensor_t *node) {
(void)eventType;
(void)node;
}
__attribute__ ((weak, alias("ptc_event_callback"))) void ptc_event_cb_touch(const ptc_cb_event_t eventType, cap_sensor_t* node);
__attribute__ ((weak, alias("ptc_event_callback"))) void ptc_event_cb_wake(const ptc_cb_event_t eventType, cap_sensor_t* node);
__attribute__ ((weak, alias("ptc_event_callback"))) void ptc_event_cb_conversion(const ptc_cb_event_t eventType, cap_sensor_t* node);
__attribute__ ((weak, alias("ptc_event_callback"))) void ptc_event_cb_calibration(const ptc_cb_event_t eventType, cap_sensor_t* node);
__attribute__ ((weak, alias("ptc_event_callback"))) void ptc_event_cb_error(const ptc_cb_event_t eventType, cap_sensor_t* node);
__attribute__ ((weak, alias("ptc_event_callback"))) void ptc_event_cb_touch(const ptc_cb_event_t eventType, cap_sensor_t *node);
__attribute__ ((weak, alias("ptc_event_callback"))) void ptc_event_cb_wake(const ptc_cb_event_t eventType, cap_sensor_t *node);
__attribute__ ((weak, alias("ptc_event_callback"))) void ptc_event_cb_conversion(const ptc_cb_event_t eventType, cap_sensor_t *node);
__attribute__ ((weak, alias("ptc_event_callback"))) void ptc_event_cb_calibration(const ptc_cb_event_t eventType, cap_sensor_t *node);
__attribute__ ((weak, alias("ptc_event_callback"))) void ptc_event_cb_error(const ptc_cb_event_t eventType, cap_sensor_t *node);



Expand All @@ -109,7 +109,7 @@ __attribute__ ((weak, alias("ptc_event_callback"))) void ptc_event_cb_error(cons
*/

// Set the threshold for touch detection and away from touch for a node
uint8_t ptc_node_set_thresholds (cap_sensor_t* node, int16_t th_in, int16_t th_out) {
uint8_t ptc_node_set_thresholds (cap_sensor_t *node, int16_t th_in, int16_t th_out) {
if (NULL == node)
return PTC_LIB_BAD_POINTER;

Expand All @@ -120,7 +120,7 @@ uint8_t ptc_node_set_thresholds (cap_sensor_t* node, int16_t th_in, int16_t th_o


// Change Resistor Setting. Note: Only has an effect on mutual sensors
uint8_t ptc_node_set_resistor(cap_sensor_t* node, uint8_t res) {
uint8_t ptc_node_set_resistor(cap_sensor_t *node, uint8_t res) {
PTC_CHECK_FOR_BAD_POINTER(node);

if (res > RSEL_MAX)
Expand All @@ -139,7 +139,7 @@ uint8_t ptc_node_set_resistor(cap_sensor_t* node, uint8_t res) {


// Change prescaler. Recommended ADC frequency: < 1.5MHz, but max 3 factors below
uint8_t ptc_node_set_prescaler(cap_sensor_t* node, uint8_t presc) {
uint8_t ptc_node_set_prescaler(cap_sensor_t *node, uint8_t presc) {
PTC_CHECK_FOR_BAD_POINTER(node);

if ((presc > (PTC_PRESC_DEFAULT + 2)) || (presc < PTC_PRESC_DEFAULT))
Expand All @@ -152,7 +152,7 @@ uint8_t ptc_node_set_prescaler(cap_sensor_t* node, uint8_t presc) {
}


uint8_t ptc_node_set_gain(cap_sensor_t* node, uint8_t aGain, uint8_t dGain) {
uint8_t ptc_node_set_gain(cap_sensor_t *node, uint8_t aGain, uint8_t dGain) {
PTC_CHECK_FOR_BAD_POINTER(node);

#if defined (__PTC_Tiny__)
Expand Down Expand Up @@ -240,7 +240,7 @@ void ptc_init_ADC0(void) {
#endif
}

uint8_t ptc_add_node(cap_sensor_t* node, uint8_t* pCh, const uint8_t type) {
uint8_t ptc_add_node(cap_sensor_t *node, uint8_t *pCh, const uint8_t type) {
const uint8_t typesize = sizeof(ptc_ch_arr_t);

uint8_t hi_node = (uint8_t)((uint16_t)node >> 8);
Expand Down Expand Up @@ -279,7 +279,7 @@ uint8_t ptc_add_node(cap_sensor_t* node, uint8_t* pCh, const uint8_t type) {
yCh |= orY;
}
if ((xCh | yCh) == 0) { /* not a single pin selected */
return PTC_LIB_BAD_ARGUMENT;
return PTC_LIB_BAD_ARGUMENT;
}
#endif

Expand Down Expand Up @@ -324,15 +324,16 @@ uint8_t ptc_add_node(cap_sensor_t* node, uint8_t* pCh, const uint8_t type) {
PORTA.PINCONFIG = PORT_PULLUPEN_bm | PORT_ISC_INPUT_DISABLE_gc; // this setting is mirrored across all PORTs (guard against ISRs)
uint8_t* pin_upd = (uint8_t*)&(PORTA.PINCTRLUPD);

for (uint8_t i = 0; i < typesize; i++) {
uint8_t pin_bm = *pCh;
pCh += typesize;
pin_bm |= *pCh;
pCh -= (typesize-1); // decrement by one less to increment to next byte

*pin_upd = pin_bm;
if ((uint8_t)(uint16_t) pin_upd == (uint8_t)(uint16_t)&PORTB.PINCTRLUPD) // double cast to remove warning, skip PORTC
pin_upd += sizeof(PORT_t);
uint8_t *end = pCh + typesize;
while (pCh < end) {
if ((uint8_t)(uint16_t) pin_upd != (uint8_t)(uint16_t)&PORTC.PINCTRLUPD) { // double cast to remove warning, skip PORTC
uint8_t pin_bm = *pCh;
pCh += typesize;
pin_bm |= *pCh;
pCh -= (typesize-1); // decrement by one less to increment to next byte

*pin_upd = pin_bm;
}
pin_upd += sizeof(PORT_t);
}
SREG = old_sreg;
Expand All @@ -343,15 +344,15 @@ uint8_t ptc_add_node(cap_sensor_t* node, uint8_t* pCh, const uint8_t type) {



uint8_t ptc_enable_node(cap_sensor_t* node) {
uint8_t ptc_enable_node(cap_sensor_t *node) {
PTC_CHECK_FOR_BAD_POINTER(node);

node->state.disabled = 0;
return PTC_LIB_SUCCESS;
}

// Will finish conversion, but not start a new one
uint8_t ptc_disable_node(cap_sensor_t* node) {
uint8_t ptc_disable_node(cap_sensor_t *node) {
PTC_CHECK_FOR_BAD_POINTER(node);

node->state.disabled = 1;
Expand Down Expand Up @@ -384,7 +385,7 @@ void ptc_set_next_conversion_type(ptc_node_type_t type) {
// ev_ch: bitmask of required channels to be used for ADC0/PTC, e.g. channel 2 and 5 -> 0x24
// this would allow to periodically start ADC0/PIT by a timer without sleep
// user must tell the function which event channel to connect to.
uint8_t ptc_lp_init(cap_sensor_t* node, uint8_t event_ch) {
uint8_t ptc_lp_init(cap_sensor_t *node, uint8_t event_ch) {
PTC_CHECK_FOR_BAD_POINTER(node);

if (NULL != lowPowerNode)
Expand Down Expand Up @@ -434,7 +435,7 @@ uint8_t ptc_lp_was_waken(void) {


/* not recommended to use, as the calculation is bloated */
uint16_t ptc_get_node_cc_femto (cap_sensor_t* node) {
uint16_t ptc_get_node_cc_femto (cap_sensor_t *node) {
if (NULL == node)
return 0;

Expand Down Expand Up @@ -509,7 +510,7 @@ void ptc_process (uint16_t currTime) {
/*
* Internal functions only below. Not part of the API
*/
void ptc_process_measurement (cap_sensor_t* node) {
void ptc_process_measurement (cap_sensor_t *node) {
if (node->state.error)
return;

Expand All @@ -522,7 +523,7 @@ void ptc_process_measurement (cap_sensor_t* node) {



void ptc_process_node_sm (cap_sensor_t* node) {
void ptc_process_node_sm (cap_sensor_t *node) {
uint16_t nodeData = node->sensorData;
uint8_t nodeSM = node->stateMachine;
uint8_t lastChange = node->lastStateChange;
Expand Down Expand Up @@ -656,7 +657,7 @@ void ptc_process_node_sm (cap_sensor_t* node) {



uint8_t ptc_process_calibrate (cap_sensor_t* node) {
uint8_t ptc_process_calibrate (cap_sensor_t *node) {
uint16_t rawData = node->sensorData;

#if defined(__PTC_Tiny__)
Expand Down Expand Up @@ -990,7 +991,7 @@ void ptc_set_registers(cap_sensor_t* node) {

pPTC->CTRLA = ADC_RUNSTBY_bm | ADC_ENABLE_bm; /* 0x81 */

if (0 == node->state.low_power)
if (0 == node->state.low_power)
pPTC->COMMAND = 0x01; // Normal operation: Manual Start
else
pPTC->EVCTRL = 0x01; // Low Power: Start by positive flank on event
Expand All @@ -1009,7 +1010,7 @@ cap_sensor_t* ptc_get_last_node (void) {
cap_sensor_t *nextNode = node->nextNode;
if (nextNode == NULL)
return node;
else
else
node = nextNode;
}
}
Expand Down Expand Up @@ -1057,7 +1058,7 @@ void ptc_eoc(void) {
pCurrentNode->state.win_comp = 0;
ptc_lib_state = PTC_LIB_CONV_LP;
}

} else {
ptc_start_conversion(pCurrentNode->nextNode);
}
Expand Down
Loading

0 comments on commit d07ec31

Please sign in to comment.