Skip to content

Commit

Permalink
Update GPIO pin modes and values
Browse files Browse the repository at this point in the history
  • Loading branch information
XQuestCode committed Jan 23, 2024
1 parent 70a8bcb commit cfeda36
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
10 changes: 5 additions & 5 deletions coresdk/src/coresdk/raspi_gpio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace splashkit_lib
{
return static_cast<pin_modes>(sk_gpio_get_mode(bcmPin));
}
return INPUT;
return GPIO_INPUT;
}

// Write a value to the given pin
Expand Down Expand Up @@ -93,13 +93,13 @@ namespace splashkit_lib
if (bcmPin == -1)
{
cout << "Reading of PIN: " << pin << " would always be HIGH" << endl;
return HIGH;
return GPIO_HIGH;
}
else if (bcmPin == -2)
{

cout << "Reading of PIN: " << pin << " would always be LOW" << endl;
return LOW;
return GPIO_LOW;
}
return static_cast<pin_values>(sk_gpio_read(bcmPin));
}
Expand Down Expand Up @@ -177,8 +177,8 @@ namespace splashkit_lib
int bcmPin = boardToBCM(static_cast<pins>(i));
if (bcmPin > 0)
{
raspi_set_mode(static_cast<pins>(bcmPin), INPUT);
raspi_write(static_cast<pins>(bcmPin), LOW);
raspi_set_mode(static_cast<pins>(bcmPin), GPIO_INPUT);
raspi_write(static_cast<pins>(bcmPin), GPIO_LOW);
}
}
sk_gpio_cleanup();
Expand Down
43 changes: 22 additions & 21 deletions coresdk/src/coresdk/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,41 +403,42 @@ enum pins
PIN_39 = 39,
PIN_40 = 40,
};
#include <cstdint>

/**
* GPIO Pin Modes:
*
* @constant INPUT - Input mode.
* @constant OUTPUT - Output mode.
* @constant ALT0 - Alternate function mode 0.
* @constant ALT1 - Alternate function mode 1.
* @constant ALT2 - Alternate function mode 2.
* @constant ALT3 - Alternate function mode 3.
* @constant ALT4 - Alternate function mode 4.
* @constant ALT5 - Alternate function mode 5.
* @constant GPIO_INPUT - Input mode.
* @constant GPIO_OUTPUT - Output mode.
* @constant GPIO_ALT0 - Alternate function mode 0.
* @constant GPIO_ALT1 - Alternate function mode 1.
* @constant GPIO_ALT2 - Alternate function mode 2.
* @constant GPIO_ALT3 - Alternate function mode 3.
* @constant GPIO_ALT4 - Alternate function mode 4.
* @constant GPIO_ALT5 - Alternate function mode 5.
*/

enum pin_modes
{
INPUT = 0,
OUTPUT = 1,
ALT0 = 4,
ALT1 = 5,
ALT2 = 6,
ALT3 = 7,
ALT4 = 3,
ALT5 = 2
GPIO_INPUT = 0,
GPIO_OUTPUT = 1,
GPIO_ALT0 = 4,
GPIO_ALT1 = 5,
GPIO_ALT2 = 6,
GPIO_ALT3 = 7,
GPIO_ALT4 = 3,
GPIO_ALT5 = 2
};

/**
* GPIO Pin Values:
*
* @constant LOW - Logic low (0).
* @constant HIGH - Logic high (1).
* @constant GPIO_LOW - Logic low (0).
* @constant GPIO_HIGH - Logic high (1).
*/
enum pin_values
{
LOW = 0,
HIGH = 1
GPIO_LOW = 0,
GPIO_HIGH = 1
};
/**
* GPIO Pull-up/Pull-down Configurations:
Expand Down
8 changes: 4 additions & 4 deletions coresdk/src/test/test_raspi_gpio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ void run_gpio_tests()

// Set GPIO pin 11 as an output
cout << "Setting GPIO pin 11 as an output" << endl;
raspi_set_mode(PIN_11, OUTPUT);
raspi_set_mode(PIN_11, GPIO_OUTPUT);

// Read the initial value of GPIO pin 11
int defaultValue = raspi_read(PIN_11);
cout << "Value of Pin 11: " << defaultValue << endl;

// Write HIGH to GPIO pin 11
cout << "Writing HIGH to GPIO pin 11" << endl;
raspi_write(PIN_11, HIGH);
raspi_write(PIN_11, GPIO_HIGH);

// Read the value of GPIO pin 11
int value = raspi_read(PIN_11);
cout << "GPIO 11 value: " << value << endl;

// Write HIGH to GPIO pin 17
cout << "Writing HIGH to GPIO pin 17" << endl;
raspi_write(PIN_17, HIGH);
raspi_write(PIN_17, GPIO_HIGH);

// Write HIGH to Ground PIN
cout << "Writing HIGH to Ground PIN" << endl;
raspi_write(PIN_6, HIGH);
raspi_write(PIN_6, GPIO_HIGH);

// Clean up the GPIO
raspi_cleanup();
Expand Down

0 comments on commit cfeda36

Please sign in to comment.