Skip to content

Commit

Permalink
gpio pull ups/pull downs
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel committed Mar 24, 2021
1 parent d3cecf8 commit 988f56a
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 19 deletions.
20 changes: 12 additions & 8 deletions system/apps_featured/test49_gpio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ cmake_minimum_required(VERSION 2.8)
cmake_policy(SET CMP0054 NEW)
cmake_policy(SET CMP0025 NEW)
project(LA140_emulator)

set(CMAKE_CXX_COMPILER clang)
set(CMAKE_SUPPRESS_REGENERATION true)
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD 11)

# call "brew install sdl2"


if (ARM)
include_directories("../../os_platform/common/include")
endif()

include_directories("../../os_host/source")

if (DESKTOP)
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})
Expand Down Expand Up @@ -42,13 +45,15 @@ file(GLOB main_src
)

file(GLOB linker_script
"../../apps/test49_gpio/app.lds"
"source/app.lds"
)
endif()

include_directories("source/")

file(GLOB application_src
"../../apps/test49_gpio/*.cpp"
"../../apps/test49_gpio/*.h"
"*.cpp"
"*.h"
)

if (DESKTOP)
Expand All @@ -69,14 +74,13 @@ source_group("include" FILES "../../os_platform/common/include")

file(GLOB application_exec
${main_src} ${bios_src} ${framework_src}
${gui_src} ${application_src} ${application_devices_src} ${application_codecs_src}
${application_layouts_src} ${application_utils_src} ${application_controls_src}
${application_layouts_file_src} ${application_layouts_meas_src} ${application_layouts_modem_src}
${gui_src} ${application_src}
)

add_executable(application ${application_exec})

add_definitions(-DEMULATED)
add_definitions(-DLA104)

if (ARM)
target_link_libraries(application m)
Expand Down
3 changes: 3 additions & 0 deletions system/apps_featured/test49_gpio/build_mac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mkdir build
cd build
cmake .. -DDESKTOP=1 -DCMAKE_INSTALL_PREFIX=../_install -GXcode
55 changes: 45 additions & 10 deletions system/apps_featured/test49_gpio/digital.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class CDigital : public CWindow
CGpio::EPin pin;
const char* id;
bool enabled;
enum {OnlyInput, Input, Output} dir;
enum {OnlyInput, Input, InputPu, InputPd, Output} dir;
bool logic;
bool prev;

Expand All @@ -16,7 +16,19 @@ class CDigital : public CWindow
if (!enabled)
return CGpio::EDirection::Disabled;
else
return dir == TRow::Output ? CGpio::EDirection::Output : CGpio::EDirection::Input;
{
switch (dir)
{
case OnlyInput: return CGpio::EDirection::Input;
case Input: return CGpio::EDirection::Input;
case InputPu: return CGpio::EDirection::InputPullUp;
case InputPd: return CGpio::EDirection::InputPullDown;
case Output: return CGpio::EDirection::Output;
default:
_ASSERT(0);
return CGpio::EDirection::Input;
}
}
}
};

Expand Down Expand Up @@ -101,10 +113,24 @@ class CDigital : public CWindow
return;
}

if (row.dir == TRow::OnlyInput)
DrawSingleToggler(_x+40, _y, "Input");
else
DrawToggler(_x+40, _y, "In", "Out", row.dir == TRow::Input ? 0 : 1, selected ? mCol - 1 : -1);
switch (row.dir)
{
case TRow::OnlyInput:
DrawSingleToggler(_x+40, _y, "Input");
break;
case TRow::Input:
DrawToggler(_x+40, _y, "In ", "Out", 0, selected ? mCol - 1 : -1);
break;
case TRow::InputPu:
DrawToggler(_x+40, _y, "In\x18", "Out", 0, selected ? mCol - 1 : -1);
break;
case TRow::InputPd:
DrawToggler(_x+40, _y, "In\x19", "Out", 0, selected ? mCol - 1 : -1);
break;
case TRow::Output:
DrawToggler(_x+40, _y, "In ", "Out", 1, selected ? mCol - 1 : -1);
break;
}

//LCD::Rectangle(CRect(_x+180, _y+1, _x+180+80, _y+14-1), gControl);

Expand Down Expand Up @@ -216,7 +242,7 @@ class CDigital : public CWindow
{
if (mConfig[mRow].dir == TRow::OnlyInput)
return;
if (mConfig[mRow].dir == TRow::Input && mCol == 2)
if (mConfig[mRow].dir != TRow::Output && mCol == 2)
return;

mCol++;
Expand All @@ -226,7 +252,8 @@ class CDigital : public CWindow
{
mRow--;

if (mConfig[mRow].dir == TRow::Input && mCol == 3)
if ((mConfig[mRow].dir == TRow::Input || mConfig[mRow].dir == TRow::InputPu ||
mConfig[mRow].dir == TRow::InputPd) && mCol == 3)
mCol = 2;

DrawLine(mRow+1);
Expand All @@ -237,7 +264,8 @@ class CDigital : public CWindow
{
mRow++;

if (mConfig[mRow].dir == TRow::Input && mCol == 3)
if ((mConfig[mRow].dir == TRow::Input || mConfig[mRow].dir == TRow::InputPu ||
mConfig[mRow].dir == TRow::InputPd) && mCol == 3)
mCol = 2;

DrawLine(mRow-1);
Expand All @@ -263,7 +291,14 @@ class CDigital : public CWindow
}
if (mCol == 1)
{
row.dir = TRow::Input;
switch (row.dir)
{
case TRow::OnlyInput: _ASSERT(0);
case TRow::Input: row.dir = TRow::InputPu; break;
case TRow::InputPu: row.dir = TRow::InputPd; break;
case TRow::InputPd: row.dir = TRow::Input; break;
case TRow::Output: row.dir = TRow::Input; break;
}
mGpio.SetDirection(row.pin, row.GetDirection());
}
if (mCol == 2)
Expand Down
8 changes: 7 additions & 1 deletion system/apps_featured/test49_gpio/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CMenuMain : public CTopMenu
class CGpio
{
public:
enum EDirection {Disabled, Input, Output};
enum EDirection {Disabled, Input, InputPullUp, InputPullDown, Output};
using EPin = BIOS::GPIO::EPin;

void SetDirection(EPin pin, EDirection dir)
Expand All @@ -35,6 +35,12 @@ class CGpio
case Input:
GPIO::PinMode(pin, GPIO::EMode::Input);
break;
case InputPullUp:
GPIO::PinMode(pin, (GPIO::EMode)(GPIO::EMode::Input | GPIO::EMode::PullUp));
break;
case InputPullDown:
GPIO::PinMode(pin, (GPIO::EMode)(GPIO::EMode::Input | GPIO::EMode::PullDown));
break;
case Output:
GPIO::PinMode(pin, GPIO::EMode::Output);
break;
Expand Down

0 comments on commit 988f56a

Please sign in to comment.