Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work on CPU GPIO #1696

Merged
merged 7 commits into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 40 additions & 43 deletions src/PAL/Include/CPU_GPIO_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@
#ifndef _DRIVERS_GPIO_DECL_H_
#define _DRIVERS_GPIO_DECL_H_ 1

#if defined (__GNUC__)
#if defined(__GNUC__)
#define __int64 long long
#endif
typedef unsigned __int64 CLR_UINT64;

#define GPIO_PIN_NONE 0xFFFFFFFF

#define GPIO_ATTRIBUTE_NONE 0x00
#define GPIO_ATTRIBUTE_INPUT 0x01
#define GPIO_ATTRIBUTE_OUTPUT 0x02
#define GPIO_ATTRIBUTE_ALTERNATE_A 0x04
#define GPIO_ATTRIBUTE_ALTERNATE_B 0x08
#define GPIO_PIN_NONE 0xFFFFFFFF

#define GPIO_ATTRIBUTE_NONE 0x00
#define GPIO_ATTRIBUTE_INPUT 0x01
#define GPIO_ATTRIBUTE_OUTPUT 0x02
#define GPIO_ATTRIBUTE_ALTERNATE_A 0x04
#define GPIO_ATTRIBUTE_ALTERNATE_B 0x08

// from declaration at src\Windows.Devices.Gpio\win_dev_gpio_native.h
typedef enum __nfpack GpioPinDriveMode
Expand All @@ -43,12 +42,12 @@ typedef enum __nfpack GpioPinValue

enum GPIO_INT_EDGE
{
GPIO_INT_NONE = 0,
GPIO_INT_EDGE_LOW = 1,
GPIO_INT_EDGE_HIGH = 2,
GPIO_INT_EDGE_BOTH = 3,
GPIO_INT_NONE = 0,
GPIO_INT_EDGE_LOW = 1,
GPIO_INT_EDGE_HIGH = 2,
GPIO_INT_EDGE_BOTH = 3,
GPIO_INT_LEVEL_HIGH = 4,
GPIO_INT_LEVEL_LOW = 5
GPIO_INT_LEVEL_LOW = 5
};

// struct GPIO_FLAG_RESISTOR
Expand All @@ -58,21 +57,19 @@ enum GPIO_INT_EDGE
// GPIO_RESISTOR Resistor;
// };

typedef void (*GPIO_INTERRUPT_SERVICE_ROUTINE)(GPIO_PIN pin, bool pinState);

typedef void (*GPIO_INTERRUPT_SERVICE_ROUTINE)( GPIO_PIN Pin, bool PinState, void* Param );

bool CPU_GPIO_Initialize ();
bool CPU_GPIO_Uninitialize ();

bool CPU_GPIO_Initialize();
bool CPU_GPIO_Uninitialize();

void CPU_GPIO_DisablePin ( GPIO_PIN Pin, GpioPinDriveMode driveMode, uint32_t alternateFunction);
void CPU_GPIO_DisablePin(GPIO_PIN Pin, GpioPinDriveMode driveMode, uint32_t alternateFunction);

//
// CPU_GPIO_EnableOutputPin
//
// Parameters :-
//
// Pin
// Pin
// The number of the input pin to be enabled.
// InitialState
// Inial value of pin
Expand All @@ -82,14 +79,14 @@ void CPU_GPIO_DisablePin ( GPIO_PIN Pin, GpioPinDriveMode driveMode, uint3
// Return Value
// true if the specified pin was successfully enabled as output; otherwise, false.
//
bool CPU_GPIO_EnableOutputPin( GPIO_PIN Pin, GpioPinValue InitialState, GpioPinDriveMode driveMode );
bool CPU_GPIO_EnableOutputPin(GPIO_PIN Pin, GpioPinValue InitialState, GpioPinDriveMode driveMode);

//
// CPU_GPIO_EnableInputPin
//
// Parameters :-
//
// pinNumber
// pinNumber
// The number of the input pin to be enabled.
// Debounce milisecs
// A value you can set to greater than 0 to enable glitch filtering (debouncing) for the number of millissecs
Expand All @@ -104,32 +101,35 @@ bool CPU_GPIO_EnableOutputPin( GPIO_PIN Pin, GpioPinValue InitialState, GpioPi
// Return Value
// true if the specified pin was successfully enabled; otherwise, false.
//
bool CPU_GPIO_EnableInputPin( GPIO_PIN pinNumber, CLR_UINT64 debounceTimeMilliseconds, GPIO_INTERRUPT_SERVICE_ROUTINE pin_ISR, void* isr_Param, GPIO_INT_EDGE intEdge, GpioPinDriveMode driveMode );
bool CPU_GPIO_EnableInputPin(
GPIO_PIN pinNumber,
CLR_UINT64 debounceTimeMilliseconds,
GPIO_INTERRUPT_SERVICE_ROUTINE pin_ISR,
void *isr_Param,
GPIO_INT_EDGE intEdge,
GpioPinDriveMode driveMode);

// Return current gpio pin state
GpioPinValue CPU_GPIO_GetPinState ( GPIO_PIN Pin );
GpioPinValue CPU_GPIO_GetPinState(GPIO_PIN Pin);

// Set state of output gpio pin
void CPU_GPIO_SetPinState ( GPIO_PIN Pin, GpioPinValue PinState );
void CPU_GPIO_SetPinState(GPIO_PIN Pin, GpioPinValue PinState);

// Check if pin is already reserved
// Returns true if pin is already reserved
bool CPU_GPIO_PinIsBusy ( GPIO_PIN Pin );
bool CPU_GPIO_PinIsBusy(GPIO_PIN Pin);

// Reserved or Unreserve gpio pin
// if clearing reserve always return true
// If reserving pin then return false if already reserved
bool CPU_GPIO_ReservePin ( GPIO_PIN Pin, bool fReserve );

// If reserving pin then return false if already reserved
bool CPU_GPIO_ReservePin(GPIO_PIN Pin, bool fReserve);

// Return count of gpio pins avaiable
int32_t CPU_GPIO_GetPinCount ();

int32_t CPU_GPIO_GetPinCount();

// Get / Set the pin debounce time in millisecs
uint32_t CPU_GPIO_GetPinDebounce(GPIO_PIN Pin);
bool CPU_GPIO_SetPinDebounce(GPIO_PIN pinNumber, CLR_UINT64 debounceTimeMilliseconds);

bool CPU_GPIO_SetPinDebounce(GPIO_PIN pinNumber, CLR_UINT64 debounceTimeMilliseconds);

// Validate pin and set drive mode
// return true if pin ok
Expand All @@ -139,20 +139,17 @@ bool CPU_GPIO_SetDriveMode(GPIO_PIN pinNumber, GpioPinDriveMode driveMode);
// return true if drive mode supported
bool CPU_GPIO_DriveModeSupported(GPIO_PIN pinNumber, GpioPinDriveMode driveMode);


// ==== Not implemented/used ====
// Retrieves an array containing the attributes of all the GPIO pins.
// Retrieves an array containing the attributes of all the GPIO pins.
// void CPU_GPIO_GetPinsMap(uint8_t* pins, size_t size);

// Retrieves the resistor modes supported by a designated GPIO pin.
//uint8_t CPU_GPIO_GetSupportedResistorModes(GPIO_PIN pin);
// Retrieves the resistor modes supported by a designated GPIO pin.
// uint8_t CPU_GPIO_GetSupportedResistorModes(GPIO_PIN pin);

// Retrieves the interrupt edge modes supported by a designated GPIO pin.
//uint8_t CPU_GPIO_GetSupportedInterruptModes(GPIO_PIN pin);

//Retrieves the GPIO attributes of a specified pin. ( none=0, input=1, output=2, altA=4, altB=8 etc )
//uint32_t CPU_GPIO_Attributes(GPIO_PIN Pin);
// Retrieves the interrupt edge modes supported by a designated GPIO pin.
// uint8_t CPU_GPIO_GetSupportedInterruptModes(GPIO_PIN pin);

// Retrieves the GPIO attributes of a specified pin. ( none=0, input=1, output=2, altA=4, altB=8 etc )
// uint32_t CPU_GPIO_Attributes(GPIO_PIN Pin);

#endif // _DRIVERS_GPIO_DECL_H_

Loading