Skip to content

Commit fe239fc

Browse files
cores/psoc6: Fix some cppcheck errors.
Signed-off-by: Ramya Subramanyam <[email protected]>
1 parent 3c8f7ae commit fe239fc

File tree

7 files changed

+103
-97
lines changed

7 files changed

+103
-97
lines changed

cores/psoc6/Uart.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ int Uart::read(void) {
120120
}
121121

122122
size_t Uart::write(uint8_t c) {
123-
return write((const uint8_t *)&c, 1);
123+
return write((const uint8_t*)&c, 1);
124124
}
125125

126-
size_t Uart::write(const uint8_t *buffer, size_t size) {
126+
size_t Uart::write(const uint8_t* buffer, size_t size) {
127127
size_t left_to_write = size;
128128
unsigned long time_start_ms = millis();
129129
uint32_t constexpr timeout_ms = 500;
@@ -138,7 +138,7 @@ size_t Uart::write(const uint8_t *buffer, size_t size) {
138138
left_to_write > num_bytes_writable ? num_bytes_writable : left_to_write;
139139
/* Trying to write 0 size will throw an exception. */
140140
if (bytes_to_write > 0) {
141-
cy_rslt_t result = cyhal_uart_write(&uart_obj, (void *)buffer, &bytes_to_write);
141+
cy_rslt_t result = cyhal_uart_write(&uart_obj, (void*)buffer, &bytes_to_write);
142142
if (result != CY_RSLT_SUCCESS) {
143143
break;
144144
}
@@ -158,8 +158,8 @@ uart_error_t Uart::getLastError() {
158158
return last_error;
159159
}
160160

161-
void Uart::uart_event_handler(void *handler_arg, cyhal_uart_event_t event) {
162-
Uart *uart = static_cast<Uart *>(handler_arg);
161+
void Uart::uart_event_handler(void* handler_arg, cyhal_uart_event_t event) {
162+
Uart* uart = static_cast<Uart*>(handler_arg);
163163
uart->IrqHandler();
164164
}
165165

cores/psoc6/Uart.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ class Uart : public arduino::HardwareSerial {
2323
int read(void);
2424
void flush(void);
2525
virtual size_t write(uint8_t c);
26-
virtual size_t write(const uint8_t *buffer, size_t size);
26+
virtual size_t write(const uint8_t* buffer, size_t size);
2727

2828
using Print::write;
2929
operator bool();
3030

3131
uart_error_t getLastError();
3232

33-
static void uart_event_handler(void *handler_arg, cyhal_uart_event_t event);
33+
static void uart_event_handler(void* handler_arg, cyhal_uart_event_t event);
3434

3535
private:
3636
pin_size_t tx_pin;

cores/psoc6/analog_io.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ void analogWriteResolution(int res) {
123123

124124
void analogWrite(pin_size_t pinNumber, int value) {
125125
uint8_t pwm_index = 0;
126+
uint8_t pwm_value = value;
126127
cy_rslt_t result = CY_RSLT_TYPE_ERROR;
127128

128129
if (pinNumber > GPIO_PIN_COUNT) {
@@ -146,19 +147,21 @@ void analogWrite(pin_size_t pinNumber, int value) {
146147
}
147148
}
148149

149-
if (value < 0) {
150-
value = 0;
151-
}
152-
if (value > desiredWriteResolution) {
153-
value = desiredWriteResolution;
154-
}
150+
if (pwm_index < PWM_HOWMANY) {
151+
if (value < 0) {
152+
pwm_value = 0;
153+
}
154+
if (value > desiredWriteResolution) {
155+
pwm_value = desiredWriteResolution;
156+
}
155157

156-
float duty_cycle_pertentage = (value / desiredWriteResolution) * 100.0f;
158+
float duty_cycle_pertentage = (pwm_value / desiredWriteResolution) * 100.0f;
157159

158-
result =
159-
cyhal_pwm_set_duty_cycle(&pwm[pwm_index].pwm_obj, duty_cycle_pertentage, PWM_FREQUENCY_HZ);
160-
pwm_assert(result);
160+
result = cyhal_pwm_set_duty_cycle(&pwm[pwm_index].pwm_obj, duty_cycle_pertentage,
161+
PWM_FREQUENCY_HZ);
162+
pwm_assert(result);
161163

162-
result = cyhal_pwm_start(&pwm[pwm_index].pwm_obj);
163-
pwm_assert(result);
164+
result = cyhal_pwm_start(&pwm[pwm_index].pwm_obj);
165+
pwm_assert(result);
166+
}
164167
}

cores/psoc6/interrupts.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void attachInterrupt(pin_size_t interruptNumber, voidFuncPtr callback, PinStatus
5353
break;
5454
}
5555

56-
gpio_callback_data.callback = (void (*)(void *, cyhal_gpio_event_t))callback;
56+
gpio_callback_data.callback = (void (*)(void*, cyhal_gpio_event_t))callback;
5757
cyhal_gpio_register_callback(pin, &gpio_callback_data);
5858
cyhal_gpio_enable_event(pin, event, GPIO_INTERRUPT_PRIORITY, true);
5959
}

cores/psoc6/main.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
TaskHandle_t arduino_main_task_handle;
3535

36-
void arduino_main_task(void *arg);
36+
void arduino_main_task(void* arg);
3737

3838
// Weak empty variant initialization function.
3939
// May be redefined by variant files.
@@ -64,7 +64,7 @@ int main(void) {
6464
return 0;
6565
}
6666

67-
void arduino_main_task(void *arg) {
67+
void arduino_main_task(void* arg) {
6868

6969
/* Enable global interrupts */
7070
interrupts();
@@ -74,8 +74,5 @@ void arduino_main_task(void *arg) {
7474

7575
for (;;) {
7676
loop();
77-
if (arduino::serialEventRun) {
78-
arduino::serialEventRun();
79-
}
8077
}
8178
}

libraries/WiFi/src/SecSocket.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef CY_SECURE_SOCKET_H
22
#define CY_SECURE_SOCKET_H
33

4+
#include "Arduino.h"
45
#include "api/IPAddress.h"
56
#include "api/RingBuffer.h"
67
#include "cy_secure_sockets.h"

variants/CY8CKIT-062S2-AI/pins_arduino.h

Lines changed: 77 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -30,102 +30,107 @@
3030

3131
/****** UART CORE DEFINES ******/
3232

33-
#define SERIAL_HOWMANY 2
34-
#define UART1_TX_PIN 32 // UART_TX P5_1
35-
#define UART1_RX_PIN 31 // UART_RX P5_0
36-
#define UART1_CTS_PIN NC // NOT CONNECTED
37-
#define UART1_RTS_PIN NC // NOT CONNECTED
38-
#define UART2_TX_PIN 10 // UART_TX P10_1
39-
#define UART2_RX_PIN 11 // UART_RX P10_0
40-
#define UART2_CTS_PIN NC // NOT CONNECTED
41-
#define UART2_RTS_PIN NC // NOT CONNECTED
42-
43-
#define I2C_HOWMANY 2
44-
#define I2C1_SDA_PIN CYBSP_I2C_SDA
45-
#define I2C1_SCL_PIN CYBSP_I2C_SCL
46-
#define I2C2_SDA_PIN P9_1
47-
#define I2C2_SCL_PIN P9_0
48-
49-
#define SPI_HOWMANY 1
50-
#define PIN_SPI_MOSI 0 // SPI-MOSI P9_0
51-
#define PIN_SPI_MISO 1 // SPI-MISO P9_1
52-
#define PIN_SPI_SCK 2 // SPI-SCLK P9_2
53-
#define PIN_SPI_SS 3 // IO_0 P9_3
54-
33+
#define SERIAL_HOWMANY 2
34+
#define UART1_TX_PIN 32 // UART_TX P5_1
35+
#define UART1_RX_PIN 31 // UART_RX P5_0
36+
#define UART1_CTS_PIN NC // NOT CONNECTED
37+
#define UART1_RTS_PIN NC // NOT CONNECTED
38+
#define UART2_TX_PIN 10 // UART_TX P10_1
39+
#define UART2_RX_PIN 11 // UART_RX P10_0
40+
#define UART2_CTS_PIN NC // NOT CONNECTED
41+
#define UART2_RTS_PIN NC // NOT CONNECTED
42+
43+
#define I2C_HOWMANY 2
44+
#define I2C1_SDA_PIN CYBSP_I2C_SDA
45+
#define I2C1_SCL_PIN CYBSP_I2C_SCL
46+
#define I2C2_SDA_PIN P9_1
47+
#define I2C2_SCL_PIN P9_0
48+
49+
#define SPI_HOWMANY 1
50+
#define PIN_SPI_MOSI 0 // SPI-MOSI P9_0
51+
#define PIN_SPI_MISO 1 // SPI-MISO P9_1
52+
#define PIN_SPI_SCK 2 // SPI-SCLK P9_2
53+
#define PIN_SPI_SS 3 // IO_0 P9_3
5554
static const uint8_t SS = PIN_SPI_SS;
56-
static const uint8_t MOSI = PIN_SPI_MOSI;
57-
static const uint8_t MISO = PIN_SPI_MISO;
55+
static const uint8_t MOSI = PIN_SPI_MOSI;
56+
static const uint8_t MISO = PIN_SPI_MISO;
5857
static const uint8_t SCK = PIN_SPI_SCK;
5958

60-
#define A0 0 // ADC P10.1
61-
#define A1 1 // ADC P10.0
59+
#define ADC_HOWMANY 2
60+
#define ADC_RESOLUTION 12 // ADC resolution in bits, but the observed range is from 0-2^11.
61+
#define PIN_A0 11 // ADC P10.0
62+
#define PIN_A1 10 // ADC P10.1
63+
static const uint8_t A0 = PIN_A0;
64+
static const uint8_t A1 = PIN_A1;
65+
66+
#define PWM_HOWMANY 14 // Number of output pins that can be PWM channels
6267

63-
#define LED1 12 // Additional LED1
64-
#define LED_BUILTIN LED1 // Standard Arduino LED: Uses LED1
65-
#define LED2 13 // Additional LED2
66-
#define BUTTON1 14 // Additional BUTTON1
67-
#define USER_BUTTON BUTTON1 // Standard Arduino USER_BUTTON: Uses BUTTON1
68+
#define LED1 12 // Additional LED1
69+
#define LED_BUILTIN LED1 // Standard Arduino LED: Uses LED1
70+
#define LED2 13 // Additional LED2
71+
#define BUTTON1 14 // Additional BUTTON1
72+
#define USER_BUTTON BUTTON1 // Standard Arduino USER_BUTTON: Uses BUTTON1
6873

6974
//****************************************************************************
7075

7176
#ifdef ARDUINO_GPIO
7277

73-
#ifdef __cplusplus
78+
#ifdef __cplusplus
7479
extern "C" {
75-
#endif
80+
#endif
7681

7782
// Mapping of digital pins and comments
7883
const cyhal_gpio_t mapping_gpio_pin[] = {
79-
/* 0 */ P9_0, // SPI-MOSI
80-
/* 1 */ P9_1, // SPI-MISO
81-
/* 2 */ P9_2, // SPI-SCLK
82-
/* 3 */ P9_3, // IO_0
83-
/* 4 */ P9_4, // IO_1
84-
/* 5 */ P9_5, // IO_2 / PWM1
85-
/* 6 */ P9_6, // IO_3 / PWM2
86-
/* 7 */ P9_7, // IO_4
87-
88-
/* 8 */ P0_2, // I2C-SCL
89-
/* 9 */ P0_3, // I2C-SDA
90-
/* 10 */ P10_1,// A1 / UART_TX
91-
/* 11 */ P10_0,// A0 / UART_RX
84+
/* 0 */ P9_0, // SPI-MOSI / PWM
85+
/* 1 */ P9_1, // SPI-MISO / PWM
86+
/* 2 */ P9_2, // SPI-SCLK / PWM
87+
/* 3 */ P9_3, // IO_0 / PWM
88+
/* 4 */ P9_4, // IO_1 / PWM
89+
/* 5 */ P9_5, // IO_2 / PWM
90+
/* 6 */ P9_6, // IO_3 / PWM
91+
/* 7 */ P9_7, // IO_4 / PWM
92+
93+
/* 8 */ P0_2, // I2C-SCL / PWM
94+
/* 9 */ P0_3, // I2C-SDA / PWM
95+
/* 10 */ P10_1, // A1 / UART_TX / PWM
96+
/* 11 */ P10_0, // A0 / UART_RX / PWM
9297

9398
// on board LEDs and USER BUTTON
9499

95-
/* 12 */ P5_3, // LED1
96-
/* 13 */ P5_4, // LED2
97-
/* 14 */ P5_2, // USER BUTTON
100+
/* 12 */ P5_3, // LED1
101+
/* 13 */ P5_4, // LED2
102+
/* 14 */ P5_2, // USER BUTTON
98103

99104
// Additional pins for expansion IO connector - J15 starting here
100105

101-
/* 15 */ P13_0,// SDHC_DATA00 / SPI-MOSI / UART_RX / I2C-SCL
102-
/* 16 */ P13_1,// SDHC_DATA01 / SPI-MISO / UART_TX / I2C-SDA
103-
/* 17 */ P13_2,// SDHC_DATA02 / SPI-SCLK / IO / PWM
104-
/* 18 */ P13_3,// SDHC_DATA03 / IO / PWM
105-
/* 19 */ P13_4,// SDHC_DATA10 / UART_RX / I2C-SCL
106-
/* 20 */ P13_5,// SDHC_DATA11 / UART_TX / I2C-SDA
107-
/* 21 */ P13_6,// SDHC_DATA12 / IO / PWM
108-
/* 22 */ P13_7,// SDHC_DATA13 / IO / PWM
109-
/* 23 */ P8_2,// SPI-SCLK / IO /PWM
110-
/* 24 */ P8_1,// SPI-MISO / UART_TX / I2C-SDA / IO / PWM
111-
/* 25 */ P8_0,// SPI-MOSI / UART_RX / I2C-SCL / IO / PWM
112-
/* 26 */ P8_3,// IO / PWM
113-
/* 27 */ P8_4,// UART_RX / I2C-SCL / IO /PWM
114-
/* 28 */ P8_5,// UART_TX / I2C-SDA / IO /PWM
115-
/* 29 */ P12_4,// SDHC_CMD / IO /PWM
116-
/* 30 */ P12_5,// SDHC_CLK / IO /PWM
117-
118-
// Debugger Serial UART pins (not available on connector)
119-
120-
/* 31 */ P5_0, // DEBUG_UART_RX
121-
/* 32 */ P5_1, // DEBUG_UART_TX
106+
/* 15 */ P13_0, // SDHC_DATA00 / SPI-MOSI / UART_RX / I2C-SCL / PWM
107+
/* 16 */ P13_1, // SDHC_DATA01 / SPI-MISO / UART_TX / I2C-SDA / PWM
108+
/* 17 */ P13_2, // SDHC_DATA02 / SPI-SCLK / IO / PWM
109+
/* 18 */ P13_3, // SDHC_DATA03 / IO / PWM
110+
/* 19 */ P13_4, // SDHC_DATA10 / UART_RX / I2C-SCL / PWM
111+
/* 20 */ P13_5, // SDHC_DATA11 / UART_TX / I2C-SDA / PWM
112+
/* 21 */ P13_6, // SDHC_DATA12 / IO / PWM
113+
/* 22 */ P13_7, // SDHC_DATA13 / IO / PWM
114+
/* 23 */ P8_2, // SPI-SCLK / IO / PWM
115+
/* 24 */ P8_1, // SPI-MISO / UART_TX / I2C-SDA / IO / PWM
116+
/* 25 */ P8_0, // SPI-MOSI / UART_RX / I2C-SCL / IO / PWM
117+
/* 26 */ P8_3, // IO / PWM
118+
/* 27 */ P8_4, // UART_RX / I2C-SCL / IO / PWM
119+
/* 28 */ P8_5, // UART_TX / I2C-SDA / IO / PWM
120+
/* 29 */ P12_4, // SDHC_CMD / IO / PWM
121+
/* 30 */ P12_5, // SDHC_CLK / IO / PWM
122+
123+
// Debugger Serial UART pins (not available on connector)
124+
125+
/* 31 */ P5_0, // DEBUG_UART_RX
126+
/* 32 */ P5_1, // DEBUG_UART_TX
122127
};
123128

124129
const uint8_t GPIO_PIN_COUNT = (sizeof(mapping_gpio_pin) / sizeof(mapping_gpio_pin[0])) - 1;
125130

126-
#ifdef __cplusplus
131+
#ifdef __cplusplus
127132
}
128-
#endif /* __cplusplus */
133+
#endif /* __cplusplus */
129134

130135
#endif /* ARDUINO_GPIO*/
131136

0 commit comments

Comments
 (0)