rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions | Variables
cypress_pins.cpp File Reference

Detailed Description

Cypress-compatible GPIO code.

Date
Jun 02, 2019
Author
Andrey Belomutskiy, (c) 2012-2020
andreika prome.nosp@m.theu.nosp@m.s.pcb.nosp@m.@gma.nosp@m.il.co.nosp@m.m

Definition in file cypress_pins.cpp.

Functions

ioportid_tgetGpioPorts ()
 
int getBrainPinIndex (brain_pin_e brainPin)
 
ioportid_t getBrainPinPort (brain_pin_e brainPin)
 
const charportname (ioportid_t GPIOx)
 
static int getPortIndex (ioportid_t port)
 
int getPortPinIndex (ioportid_t port, ioportmask_t pin)
 
ioportid_t getHwPort (const char *msg, brain_pin_e brainPin)
 
ioportmask_t getHwPin (const char *msg, brain_pin_e brainPin)
 
brain_pin_e parseBrainPin (const char *str)
 
unsigned int getBrainPinOnchipNum (void)
 
void debugBrainPin (char *buffer, size_t, brain_pin_e)
 

Variables

static ioportid_t ports []
 
static brain_pin_e portMap [16]
 

Function Documentation

◆ debugBrainPin()

void debugBrainPin ( char buffer,
size_t  size,
brain_pin_e  brainPin 
)

Definition at line 199 of file cypress_pins.cpp.

200{
201 buffer[0] = '\0';
202}
static BigBufferHandle buffer

◆ getBrainPinIndex()

int getBrainPinIndex ( brain_pin_e  brainPin)

Definition at line 39 of file cypress_pins.cpp.

39 {
40 return (brainPin - Gpio::A0) % PORT_SIZE;
41}

Referenced by getHwPin().

Here is the caller graph for this function:

◆ getBrainPinOnchipNum()

unsigned int getBrainPinOnchipNum ( void  )

Definition at line 195 of file cypress_pins.cpp.

195 {
196 return BRAIN_PIN_ONCHIP_PINS;
197}

◆ getBrainPinPort()

ioportid_t getBrainPinPort ( brain_pin_e  brainPin)

Definition at line 43 of file cypress_pins.cpp.

43 {
44 return getGpioPorts()[(brainPin - Gpio::A0) / PORT_SIZE];
45}
ioportid_t * getGpioPorts()

◆ getGpioPorts()

ioportid_t * getGpioPorts ( )

Definition at line 35 of file cypress_pins.cpp.

35 {
36 return ports;
37}
static ioportid_t ports[]

Referenced by getBrainPinPort(), and getHwPort().

Here is the caller graph for this function:

◆ getHwPin()

ioportmask_t getHwPin ( const char msg,
brain_pin_e  brainPin 
)

this method returns the numeric part of pin name. For instance, for PC13 this would return '13'

Definition at line 153 of file cypress_pins.cpp.

153 {
154 if (!isBrainPinValid(brainPin))
155 return EFI_ERROR_CODE;
156
157 if (brain_pin_is_onchip(brainPin))
158 return getBrainPinIndex(brainPin);
159
160 firmwareError(ObdCode::CUSTOM_ERR_INVALID_PIN, "%s: Invalid on-chip Gpio: %d", msg, brainPin);
161 return EFI_ERROR_CODE;
162}
int getBrainPinIndex(brain_pin_e brainPin)
void firmwareError(ObdCode code, const char *fmt,...)
@ CUSTOM_ERR_INVALID_PIN
bool brain_pin_is_onchip(brain_pin_e brainPin)
bool isBrainPinValid(brain_pin_e brainPin)

◆ getHwPort()

ioportid_t getHwPort ( const char msg,
brain_pin_e  brainPin 
)

Definition at line 137 of file cypress_pins.cpp.

137 {
138 (void)msg;
139
140 if (!isBrainPinValid(brainPin)) {
141/*
142 * https://github.com/dron0gus please help
143 firmwareError(ObdCode::CUSTOM_ERR_INVALID_PIN, "%s: Invalid Gpio: %d", msg, brainPin);
144 */
145 return nullptr;
146 }
147 return getGpioPorts()[(brainPin - Gpio::A0) / PORT_SIZE];
148}

◆ getPortIndex()

static int getPortIndex ( ioportid_t  port)
static

Definition at line 90 of file cypress_pins.cpp.

90 {
91 efiAssert(ObdCode::CUSTOM_ERR_ASSERT, port != NULL, "null port", -1);
92 if (port == GPIOA)
93 return 0;
94 if (port == GPIOB)
95 return 1;
96 if (port == GPIOC)
97 return 2;
98 if (port == GPIOD)
99 return 3;
100#if defined(GPIOF)
101 if (port == GPIOE)
102 return 4;
103#endif /* GPIOE */
104#if defined(GPIOF)
105 if (port == GPIOF)
106 return 5;
107#endif /* GPIOF */
108#if defined(GPIOG)
109 if (port == GPIOG)
110 return 6;
111#endif /* GPIOG */
112#if defined(GPIOH)
113 if (port == GPIOH)
114 return 7;
115#endif /* GPIOH */
116#if defined(GPIOI)
117 if (port == GPIOI)
118 return 8;
119#endif /* STM32_HAS_GPIOI */
120#if defined(GPIOJ_BASE)
121 if (port == GPIOJ)
122 return 9;
123#endif /* GPIOJ_BASE */
124#if defined(GPIOK_BASE)
125 if (port == GPIOK)
126 return 10;
127#endif /* GPIOK_BASE */
129 return -1;
130}
@ CUSTOM_ERR_UNKNOWN_PORT
@ CUSTOM_ERR_ASSERT

Referenced by getPortPinIndex().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPortPinIndex()

int getPortPinIndex ( ioportid_t  port,
ioportmask_t  pin 
)

Definition at line 132 of file cypress_pins.cpp.

132 {
133 int portIndex = getPortIndex(port);
134 return portIndex * PORT_SIZE + pin;
135}
static int getPortIndex(ioportid_t port)
brain_pin_e pin
Definition stm32_adc.cpp:15

◆ parseBrainPin()

brain_pin_e parseBrainPin ( const char str)

Parse string representation of physical pin into brain_pin_e ordinal.

Returns
Gpio::Unassigned for "none", Gpio::Invalid for invalid entry

Definition at line 169 of file cypress_pins.cpp.

169 {
170 if (strEqual(str, "none"))
171 return Gpio::Unassigned;
172 // todo: create method toLowerCase?
173 if (str[0] != 'p' && str[0] != 'P') {
174 return Gpio::Invalid;
175 }
176 char port = str[1];
177 if (port >= 'a' && port <= 'z') {
178 port = 10 + (port - 'a');
179 } else if (port >= 'A' && port <= 'Z') {
180 port = 10 + (port - 'A');
181 } else if (port >= '0' && port <= '9') {
182// cypress-specific code
183 port = 0 + (port - '0');
184 } else {
185 return Gpio::Invalid;
186 }
187 brain_pin_e basePin = portMap[(int)port];
188 if (basePin == Gpio::Invalid)
189 return Gpio::Invalid;
190 const char *pinStr = str + 2;
191 int pin = atoi(pinStr);
192 return basePin + pin;
193}
@ Unassigned
@ Invalid
static brain_pin_e portMap[16]

◆ portname()

const char * portname ( ioportid_t  GPIOx)
Deprecated:

Definition at line 50 of file cypress_pins.cpp.

50 {
51 if (GPIOx == GPIOA)
52 return "PA";
53 if (GPIOx == GPIOB)
54 return "PB";
55 if (GPIOx == GPIOC)
56 return "PC";
57 if (GPIOx == GPIOD)
58 return "PD";
59#if defined(GPIOF)
60 if (GPIOx == GPIOE)
61 return "PE";
62#endif /* GPIOE */
63#if defined(GPIOF)
64 if (GPIOx == GPIOF)
65 return "PF";
66#endif /* GPIOF */
67#if defined(GPIOG)
68 if (GPIOx == GPIOG)
69 return "PG";
70#endif /* GPIOG */
71#if defined(GPIOH)
72 if (GPIOx == GPIOH)
73 return "PH";
74#endif /* GPIOH */
75#if defined(GPIOI)
76 if (GPIOx == GPIOI)
77 return "PI";
78#endif /* GPIOI */
79#if defined(GPIOJ_BASE)
80 if (GPIOx == GPIOJ)
81 return "PJ";
82#endif /* GPIOJ_BASE */
83#if defined(GPIOK_BASE)
84 if (GPIOx == GPIOK)
85 return "PK";
86#endif /* GPIOK_BASE */
87 return "unknown";
88}

Variable Documentation

◆ portMap

brain_pin_e portMap[16]
static

◆ ports

ioportid_t ports[]
static
Initial value:
= {
GPIOA,
GPIOB,
GPIOC,
GPIOD,
GPIOE,
GPIOF,
GPIOG,
GPIOH,
GPIOI,
GPIOJ,
GPIOK,
}

Definition at line 14 of file cypress_pins.cpp.

14 {
15 GPIOA,
16 GPIOB,
17 GPIOC,
18 GPIOD,
19 GPIOE,
20 GPIOF,
21 GPIOG,
22 GPIOH,
23 GPIOI,
24 GPIOJ,
25 GPIOK,
26};

Referenced by getGpioPorts().

Go to the source code of this file.