Arduino Core for STM32  1.0
wirish.cpp File Reference
#include "wirish.h"
Include dependency graph for wirish.cpp:

Classes

struct  IRQLine
 

Macros

#define NUM_IRQ_LINES   (sizeof(irqlines) / sizeof(IRQLine))
 

Functions

bool pinExists (GPIO_TypeDef *GPIOx, uint16_t PPin)
 Checks if pin is available on MCU. More...
 
bool pinExists (uint8_t Pin)
 Checks if pin is available on MCU. More...
 
uint8_t PortAndPinToPinNum (GPIO_TypeDef *GPIOx, uint16_t PPin)
 Converts GPIOx port and it's pin to Arduino like pin number. More...
 
uint8_t pinMode (GPIO_TypeDef *GPIOx, uint16_t PPin, WiringPinMode mode, uint32_t speed)
 Sets mode of selected pin. More...
 
bool enableGPIO (GPIO_TypeDef *GPIOx, bool enable)
 Enables/Disables GPIO port periphery. More...
 
uint8_t pinMode (uint8_t Pin, WiringPinMode mode, uint32_t speed)
 Sets mode of selected pin. More...
 
bool canSetInterruptOnPin (uint8_t Pin)
 Checks if EXTI line, that belongs to Pin is not used by other pin's interrupt. More...
 
GPIO_TypeDef * getInterruptGPIOfromPin (uint16_t Pin)
 Gets, what GPIO is attached to EXTI line, that belongs to PPin. More...
 
bool isInterruptSetOnPin (uint8_t Pin)
 Checks Pin is used as interrupt. More...
 
uint32_t getPinPullSetting (GPIO_TypeDef *GPIOx, uint8_t INTPin)
 This function should return actual pin pull setting (GPIO_NOPULL, GPIO_PULLUP, GPIO_PULLDOWN) More...
 
uint32_t getPinSpeedSetting (GPIO_TypeDef *GPIOx, uint8_t INTPin)
 This should return actual pin toggle speed setting. More...
 
int8_t attachInterrupt (uint8_t Pin, std::function< void(void)> handler, int mode)
 Attaches interrupt to selected pin. More...
 
int8_t detachInterrupt (uint8_t Pin, bool disableEXTIwhenNotUsed)
 Detaches interrupt from selected pin and sets pin mode to INPUT. More...
 
void InterruptHandler (uint8_t lineFrom, uint8_t lineTo)
 Include this in every EXTI interrupt handler for lines 0-15. More...
 
bool WirishInit (void)
 Initializes some wirish functions. More...
 
void __attribute__ ((optimize("Ofast"))) delayMicroseconds(int32_t microseconds)
 
unsigned long random (unsigned long from, unsigned long to)
 The random function generates pseudo-random numbers. More...
 
unsigned long random (unsigned long to)
 The random function generates pseudo-random numbers. More...
 
void randomSeed (unsigned long seed)
 Initializes the pseudo-random number generator, causing it to start at an arbitrary point in its random sequence. More...
 
const char * getResetCauseName ()
 Gets the system reset cause as an ASCII-printable name string from a reset cause type. More...
 

Variables

GPIO_TypeDef * GPIO_Conversion_Table []
 
IRQLine irqlines []
 
bool WirishInitDone = true
 
unsigned long _Randomseed = 1
 
ResetCause rst_cs = reset_cause_read()
 

Macro Definition Documentation

◆ NUM_IRQ_LINES

#define NUM_IRQ_LINES   (sizeof(irqlines) / sizeof(IRQLine))

Function Documentation

◆ pinExists() [1/2]

bool pinExists ( GPIO_TypeDef *  GPIOx,
uint16_t  PPin 
)

Checks if pin is available on MCU.

Parameters
GPIOxGPIO port periphery.
PPinPin of that port to convert (GPIO_PIN_0, GPIO_PIN_1, ...). Do not use combined pins (e.g. GPIO_PIN_0 | GPIO_PIN_1)
Returns
Returns true if pin is available on MCU.

◆ pinExists() [2/2]

bool pinExists ( uint8_t  Pin)

Checks if pin is available on MCU.

Parameters
PinArduino like pin number.
Returns
Returns true if pin is available on MCU.
Here is the call graph for this function:

◆ PortAndPinToPinNum()

uint8_t PortAndPinToPinNum ( GPIO_TypeDef *  GPIOx,
uint16_t  PPin 
)

Converts GPIOx port and it's pin to Arduino like pin number.

Parameters
GPIOxGPIO port.
PPinPin of that port to convert (GPIO_PIN_0, GPIO_PIN_1, ...). Do not use combined pins (e.g. GPIO_PIN_0 | GPIO_PIN_1)
Returns
Returns Arduino like pin number (Pin).

◆ pinMode() [1/2]

uint8_t pinMode ( GPIO_TypeDef *  GPIOx,
uint16_t  PPin,
WiringPinMode  mode,
uint32_t  speed 
)

Sets mode of selected pin.

Parameters
GPIOxGPIO port.
PPinPin of that port (GPIO_PIN_0, GPIO_PIN_1, ...).
modePin mode that will be set.
See also
WiringPinMode
Parameters
speedToggle speed of pin. Available values: GPIO_SPEED_FREQ_LOW, GPIO_SPEED_FREQ_MEDIUM, GPIO_SPEED_FREQ_HIGH, GPIO_SPEED_FREQ_VERY_HIGH (only some MCUs supports this speed setting))
Returns
W_OK when pin is successfully set.
Here is the call graph for this function:

◆ enableGPIO()

bool enableGPIO ( GPIO_TypeDef *  GPIOx,
bool  enable 
)

Enables/Disables GPIO port periphery.

Parameters
GPIOxGPIO port periphery.
enableIf true, periphery will be enabled, else disabled.
Returns
Returns true when GPIO periphery was enabled successfully.

◆ pinMode() [2/2]

uint8_t pinMode ( uint8_t  Pin,
WiringPinMode  mode,
uint32_t  speed 
)

Sets mode of selected pin.

Parameters
PinArduino like pin number.
modePin mode that will be set.
See also
WiringPinMode
Parameters
speedToggle speed of pin. Available values: GPIO_SPEED_FREQ_LOW, GPIO_SPEED_FREQ_MEDIUM, GPIO_SPEED_FREQ_HIGH, GPIO_SPEED_FREQ_VERY_HIGH (only some MCUs supports this speed setting))
Returns
W_OK when pin is successfully set.
Here is the call graph for this function:

◆ canSetInterruptOnPin()

bool canSetInterruptOnPin ( uint8_t  Pin)

Checks if EXTI line, that belongs to Pin is not used by other pin's interrupt.

Parameters
PinArduino like pin number.
Returns
Returns true if you can set interrupt on Pin.
Here is the call graph for this function:

◆ getInterruptGPIOfromPin()

GPIO_TypeDef* getInterruptGPIOfromPin ( uint16_t  Pin)

Gets, what GPIO is attached to EXTI line, that belongs to PPin.

Parameters
PinArduino like pin number.
Returns
Returns pointer to GPIO_TypeDef which is attached to EXTI line, that belongs to PPin. It can return NULL when no interrupt is attached at EXTI line, that belongs to PPin.

◆ isInterruptSetOnPin()

bool isInterruptSetOnPin ( uint8_t  Pin)

Checks Pin is used as interrupt.

Parameters
PinArduino like pin number.
Returns
Returns true Pin is used as interrupt.
Note
This function looks same as negation of canSetInterruptOnPin(), but there is big difference. Assume we have attached interrupt on pin PA1:
//GPIOA
bool val = !canSetInterruptOnPin(PA1) // val == true
bool val = isInterruptSetOnPin(PA1) // val == true
//GPIOB
bool val = !canSetInterruptOnPin(PB1) // val == true
bool val = isInterruptSetOnPin(PB1) // val == false
Here is the call graph for this function:

◆ getPinPullSetting()

uint32_t getPinPullSetting ( GPIO_TypeDef *  GPIOx,
uint8_t  INTPin 
)

This function should return actual pin pull setting (GPIO_NOPULL, GPIO_PULLUP, GPIO_PULLDOWN)

Parameters
GPIOxGPIO port.
INTPinInterrupt pin number (0-15).
Note
On some MCUs, when pin mode is set to OUTPUT, pull register is cleared and this method returns always GPIO_NOPULL.
Returns
Actual pin pull setting (GPIO_NOPULL, GPIO_PULLUP, GPIO_PULLDOWN).

◆ getPinSpeedSetting()

uint32_t getPinSpeedSetting ( GPIO_TypeDef *  GPIOx,
uint8_t  INTPin 
)

This should return actual pin toggle speed setting.

Parameters
GPIOxGPIO port.
INTPinInterrupt pin number (0-15).
Note
On some MCUs, when pin mode is set to INPUT, speed register is cleared and this method returns always GPIO_SPEED_FREQ_LOW.
Returns
Actual pin toggle speed setting.

◆ attachInterrupt()

int8_t attachInterrupt ( uint8_t  Pin,
std::function< void(void)>  ,
int  mode 
)

Attaches interrupt to selected pin.

Parameters
PinArduino like pin.
handlerFunction, that will be called when interrupt is triggered.
modeMode of interrupt (RISING, FALLING, CHANGE).
Note
Every STM MCU has only 16 EXTI lines. Every line is connected to pins with same PPin number on every GPIO. It means, you cannot attach interrupt to pin PA1 and PB1 at same time. You have to choose another pin, for example PB2 or PA2.
When you attach interrupt on some pin, it will be set to INPUT mode automatically.
Returns
W_OK when interrupt was attached successfully.
Here is the call graph for this function:

◆ detachInterrupt()

int8_t detachInterrupt ( uint8_t  Pin,
bool  disableEXTIwhenNotUsed = false 
)

Detaches interrupt from selected pin and sets pin mode to INPUT.

Parameters
PinArduino like pin number.
disableEXTIwhenNotUsedTrue if you want to disable group of EXTI lines when they are not used yet. It can save energy, but it can also disable GPIO interrupt, that is set using .ioc file.
Note
When you detach interrupt on some pin, it will be set to INPUT mode automatically.
Returns
W_OK when interrupt was detached successfully.
Here is the call graph for this function:

◆ InterruptHandler()

void InterruptHandler ( uint8_t  lineFrom,
uint8_t  lineTo 
)

Include this in every EXTI interrupt handler for lines 0-15.

Parameters
lineFromSpecify first handler line
lineToSpecify last handler line
See also
interrupt.h

◆ WirishInit()

bool WirishInit ( void  )

Initializes some wirish functions.

Note
This method is automatically called before main method, so you don't have to include it in your program.
Returns
Returns true when initialization was done correctly.

◆ __attribute__()

void __attribute__ ( (optimize("Ofast"))  )

◆ random() [1/2]

unsigned long random ( unsigned long  from,
unsigned long  to 
)

The random function generates pseudo-random numbers.

Parameters
fromLower bound of the random value, inclusive (optional).
toUpper bound of the random value, exclusive.
Returns
A random number between from and to-1 or professionally said random number in interval <from,to).

◆ random() [2/2]

unsigned long random ( unsigned long  to)

The random function generates pseudo-random numbers.

Parameters
toUpper bound of the random value, exclusive.
Returns
A random number between 0 and to-1 or professionally said random number in interval <0,to).
Here is the call graph for this function:

◆ randomSeed()

void randomSeed ( unsigned long  seed)

Initializes the pseudo-random number generator, causing it to start at an arbitrary point in its random sequence.

This sequence, while very long, and random, is always the same.

Parameters
seedNumber to initialize the pseudo-random sequence.

◆ getResetCauseName()

const char* getResetCauseName ( )

Gets the system reset cause as an ASCII-printable name string from a reset cause type.

Parameters
reset_causeThe previously-obtained system reset cause
Returns
A null-terminated ASCII name string describing the system reset cause

Variable Documentation

◆ GPIO_Conversion_Table

GPIO_TypeDef* GPIO_Conversion_Table[]

◆ irqlines

IRQLine irqlines[]

◆ WirishInitDone

bool WirishInitDone = true

◆ _Randomseed

unsigned long _Randomseed = 1

◆ rst_cs

ResetCause rst_cs = reset_cause_read()
canSetInterruptOnPin
bool canSetInterruptOnPin(uint8_t Pin)
Checks if EXTI line, that belongs to Pin is not used by other pin's interrupt.
Definition: wirish.cpp:459
isInterruptSetOnPin
bool isInterruptSetOnPin(uint8_t Pin)
Checks Pin is used as interrupt.
Definition: wirish.cpp:557