Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Commit

Permalink
Added constants for the usual GPIO pins
Browse files Browse the repository at this point in the history
  • Loading branch information
Eleonore Mizo committed Apr 27, 2023
1 parent bf6656d commit 129a1d8
Show file tree
Hide file tree
Showing 15 changed files with 183 additions and 43 deletions.
1 change: 1 addition & 0 deletions build/unix/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -1839,6 +1839,7 @@ commonsrc += \
../../src/mfx/hw/GpioAccess.cpp \
../../src/mfx/hw/GpioAccess.h \
../../src/mfx/hw/GpioAccess.hpp \
../../src/mfx/hw/GpioPin.h \
../../src/mfx/hw/GpioPwm.cpp \
../../src/mfx/hw/GpioPwm.h \
../../src/mfx/hw/LedPi3.cpp \
Expand Down
1 change: 1 addition & 0 deletions build/win/mfxlib/mfxlib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,7 @@
<ClInclude Include="..\..\..\src\mfx\hw\FileIOWindows.h" />
<ClInclude Include="..\..\..\src\mfx\hw\GpioAccess.h" />
<ClInclude Include="..\..\..\src\mfx\hw\GpioAccess.hpp" />
<ClInclude Include="..\..\..\src\mfx\hw\GpioPin.h" />
<ClInclude Include="..\..\..\src\mfx\hw\GpioPwm.h" />
<ClInclude Include="..\..\..\src\mfx\hw\IoWindows.h" />
<ClInclude Include="..\..\..\src\mfx\hw\LedPi3.h" />
Expand Down
3 changes: 3 additions & 0 deletions build/win/mfxlib/mfxlib.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -5613,6 +5613,9 @@
<ClInclude Include="..\..\..\src\mfx\doc\ActionProg.h">
<Filter>mfx\doc</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\mfx\hw\GpioPin.h">
<Filter>mfx\hw</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\src\mfx\piapi\PluginInterface.cpp">
Expand Down
17 changes: 6 additions & 11 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
#else
#include "mfx/hw/DisplayPi3St7920.h"
#endif
#include "mfx/hw/GpioPin.h"
#include "mfx/hw/LedPi3.h"
#include "mfx/hw/UserInputPi3.h"

Expand Down Expand Up @@ -183,12 +184,6 @@



#if (fstb_SYS == fstb_SYS_LINUX) && ! defined (MAIN_USE_VOID)
static const int MAIN_pin_reset = 18;
#endif // fstb_SYS_LINUX, MAIN_USE_VOID



class Context
: public mfx::ModelObserverDefault
, public mfx::adrv::CbInterface
Expand Down Expand Up @@ -808,18 +803,18 @@ int WINAPI WinMain (::HINSTANCE instance, ::HINSTANCE prev_instance, ::LPSTR cmd
#if fstb_SYS == fstb_SYS_LINUX && ! defined (MAIN_USE_VOID)
::wiringPiSetupPhys ();

::pinMode (22, INPUT);
if (::digitalRead (22) == LOW)
::pinMode (mfx::hw::GpioPin::_nav_cancel, INPUT);
if (::digitalRead (mfx::hw::GpioPin::_nav_cancel) == LOW)
{
fprintf (stderr, "Emergency exit\n");
throw 0;
}

::pinMode (MAIN_pin_reset, OUTPUT);
::pinMode (mfx::hw::GpioPin::_reset, OUTPUT);

::digitalWrite (MAIN_pin_reset, LOW);
::digitalWrite (mfx::hw::GpioPin::_reset, LOW);
std::this_thread::sleep_for (std::chrono::milliseconds (100));
::digitalWrite (MAIN_pin_reset, HIGH);
::digitalWrite (mfx::hw::GpioPin::_reset, HIGH);
std::this_thread::sleep_for (std::chrono::milliseconds (100));
#endif

Expand Down
13 changes: 7 additions & 6 deletions src/mfx/adrv/DPvabDirect.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ To Public License, Version 2, as published by Sam Hocevar. See

#include "fstb/AllocAlign.h"
#include "mfx/adrv/DriverInterface.h"
#include "mfx/hw/GpioPin.h"

#include <atomic>
#include <condition_variable>
Expand Down Expand Up @@ -95,12 +96,12 @@ class DPvabDirect final
#endif // mfx_adrv_DPvabDirect_CTRL_PORT_MODE

// GPIO pins (BCM numbering, not WiringPi)
static const int _pin_rst = 5; // W - Reset pin (0 = reset, 1 = working)
static const int _pin_freq = 6; // W - Frequency selection (0 = 48 kHz, 1 = 44.1 kHz)
static const int _pin_bclk = 18; // R - I2S bit clock
static const int _pin_lrck = 19; // R - I2S word selection (0 = L, 1 = R)
static const int _pin_din = 20; // R - I2S data input (codec to cpu)
static const int _pin_dout = 21; // W - I2S data output (cpu to codec)
static const int _pin_rst = hw::GpioPin::_snd_reset; // W - Reset pin (0 = reset, 1 = working)
static const int _pin_freq = hw::GpioPin::_snd_sfreq; // W - Frequency selection (0 = 48 kHz, 1 = 44.1 kHz)
static const int _pin_bclk = hw::GpioPin::_snd_bclk; // R - I2S bit clock
static const int _pin_lrck = hw::GpioPin::_snd_lrck; // R - I2S word selection (0 = L, 1 = R)
static const int _pin_din = hw::GpioPin::_snd_din; // R - I2S data input (codec to cpu)
static const int _pin_dout = hw::GpioPin::_snd_dout; // W - I2S data output (cpu to codec)

DPvabDirect ();
virtual ~DPvabDirect ();
Expand Down
13 changes: 7 additions & 6 deletions src/mfx/adrv/DPvabI2s.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ To Public License, Version 2, as published by Sam Hocevar. See
#include "fstb/AllocAlign.h"
#include "mfx/adrv/DriverInterface.h"
#include "mfx/hw/GpioAccess.h"
#include "mfx/hw/GpioPin.h"
#include "mfx/hw/MmapPtr.h"

#include <atomic>
Expand Down Expand Up @@ -68,12 +69,12 @@ class DPvabI2s final
static const int _i2c_addr = 0x10 + 0;

// GPIO pins (BCM numbering, not WiringPi)
static const int _pin_rst = 5; // W - Reset pin (0 = reset, 1 = working)
static const int _pin_freq = 6; // W - Frequency selection (0 = 48 kHz, 1 = 44.1 kHz)
static const int _pin_bclk = 18; // R - I2S bit clock
static const int _pin_lrck = 19; // R - I2S word selection (0 = L, 1 = R)
static const int _pin_din = 20; // R - I2S data input (codec to cpu)
static const int _pin_dout = 21; // W - I2S data output (cpu to codec)
static const int _pin_rst = hw::GpioPin::_snd_reset; // W - Reset pin (0 = reset, 1 = working)
static const int _pin_freq = hw::GpioPin::_snd_sfreq; // W - Frequency selection (0 = 48 kHz, 1 = 44.1 kHz)
static const int _pin_bclk = hw::GpioPin::_snd_bclk; // R - I2S bit clock
static const int _pin_lrck = hw::GpioPin::_snd_lrck; // R - I2S word selection (0 = L, 1 = R)
static const int _pin_din = hw::GpioPin::_snd_din; // R - I2S data input (codec to cpu)
static const int _pin_dout = hw::GpioPin::_snd_dout; // W - I2S data output (cpu to codec)

DPvabI2s ();
virtual ~DPvabI2s ();
Expand Down
13 changes: 7 additions & 6 deletions src/mfx/adrv/DPvabI2sDma.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ To Public License, Version 2, as published by Sam Hocevar. See
#include "fstb/AllocAlign.h"
#include "mfx/adrv/DriverInterface.h"
#include "mfx/hw/GpioAccess.h"
#include "mfx/hw/GpioPin.h"
#include "mfx/hw/MmapPtr.h"
#include "mfx/hw/RPiDmaBlocks.h"

Expand Down Expand Up @@ -97,22 +98,22 @@ class DPvabI2sDma final
// GPIO pins (BCM numbering, not WiringPi)

// W - Reset pin (0 = reset, 1 = working)
static constexpr int _pin_rst = 5;
static constexpr int _pin_rst = hw::GpioPin::_snd_reset;

// W - Sampling rate selection (see _fs_code)
static constexpr int _pin_freq = 6;
static constexpr int _pin_freq = hw::GpioPin::_snd_sfreq;

// R - I2S bit clock
static constexpr int _pin_bclk = 18;
static constexpr int _pin_bclk = hw::GpioPin::_snd_bclk;

// R - I2S word selection (0 = L, 1 = R)
static constexpr int _pin_lrck = 19;
static constexpr int _pin_lrck = hw::GpioPin::_snd_lrck;

// R - I2S data input (codec to CPU)
static constexpr int _pin_din = 20;
static constexpr int _pin_din = hw::GpioPin::_snd_din;

// W - I2S data output (CPU to codec)
static constexpr int _pin_dout = 21;
static constexpr int _pin_dout = hw::GpioPin::_snd_dout;

// - - - - - - - - - - - - - - - - - - - - - - - -

Expand Down
7 changes: 4 additions & 3 deletions src/mfx/hw/DisplayPi3Pcd8544.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ To Public License, Version 2, as published by Sam Hocevar. See
#include "conc/CellPool.h"
#include "conc/LockFreeCell.h"
#include "conc/LockFreeQueue.h"
#include "mfx/hw/GpioPin.h"
#include "mfx/ui/DisplayInterface.h"
#include "mfx/ui/TimeShareCbInterface.h"

Expand Down Expand Up @@ -69,9 +70,9 @@ class DisplayPi3Pcd8544 final
static const int _spi_port = 1;
static const int _spi_rate = 1 * 1000*1000; // Hz

static const int _pin_dc = 12;
static const int _pin_cs = 16;
static const int _pin_rst = 18;
static const int _pin_dc = GpioPin::_pcd8544_dc;
static const int _pin_cs = GpioPin::_pcd8544_cs;
static const int _pin_rst = GpioPin::_reset;



Expand Down
5 changes: 3 additions & 2 deletions src/mfx/hw/DisplayPi3St7920.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ To Public License, Version 2, as published by Sam Hocevar. See
#include "conc/CellPool.h"
#include "conc/LockFreeCell.h"
#include "conc/LockFreeQueue.h"
#include "mfx/hw/GpioPin.h"
#include "mfx/ui/DisplayInterface.h"
#include "mfx/ui/TimeShareCbInterface.h"

Expand Down Expand Up @@ -69,8 +70,8 @@ class DisplayPi3St7920 final
static const int _spi_port = 1;
static const int _spi_rate = 1 * 1000*1000; // Hz.

static const int _pin_cs = 16; // Chip select (RS)
static const int _pin_rst = 18; // Reset (RST)
static const int _pin_cs = GpioPin::_st7920_cs; // Chip select (RS)
static const int _pin_rst = GpioPin::_reset; // Reset (RST)



Expand Down
125 changes: 125 additions & 0 deletions src/mfx/hw/GpioPin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*****************************************************************************
GpioPin.h
Author: Laurent de Soras, 2023
References all the GPIO pins used in the program.
--- Legal stuff ---
This program is free software. It comes without any warranty, to
the extent permitted by applicable law. You can redistribute it
and/or modify it under the terms of the Do What The Fuck You Want
To Public License, Version 2, as published by Sam Hocevar. See
http://www.wtfpl.net/ for more details.
*Tab=3***********************************************************************/



#pragma once
#if ! defined (mfx_hw_GpioPin_HEADER_INCLUDED)
#define mfx_hw_GpioPin_HEADER_INCLUDED

#if defined (_MSC_VER)
#pragma warning (4 : 4250)
#endif



/*\\\ INCLUDE FILES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/



namespace mfx
{
namespace hw
{



class GpioPin
{

/*\\\ PUBLIC \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/

public:

// - - - - - - - - - - - - - - - - - - - - - - - -
// Physical numbering

// Shared
static constexpr int _reset = 18; // GPIO 24 / phys 18

// Switches
static constexpr int _nav_ok = 7; // GPIO 4 / phys 7
static constexpr int _nav_cancel = 22; // GPIO 25 / phys 22

// LEDs
static constexpr int _led_0 = 11; // GPIO 17 / phys 11
static constexpr int _led_1 = 13; // GPIO 27 / phys 13
static constexpr int _led_2 = 15; // GPIO 22 / phys 15

// Small Nokia display (never acually used)
static constexpr int _pcd8544_dc = 12; // GPIO 18 / phys 12
static constexpr int _pcd8544_cs = 16; // GPIO 23 / phys 16

// 128x64 display (SPI)
static constexpr int _st7920_cs = 16; // GPIO 23 / phys 16

// - - - - - - - - - - - - - - - - - - - - - - - -
// BCM numbering (GPIO)

// Audio interface (I2S)
static constexpr int _snd_reset = 5; // GPIO 5 / phys 29
static constexpr int _snd_sfreq = 6; // GPIO 6 / phys 31
static constexpr int _snd_bclk = 18; // GPIO 18 / phys 12
static constexpr int _snd_lrck = 19; // GPIO 19 / phys 35
static constexpr int _snd_din = 20; // GPIO 20 / phys 38
static constexpr int _snd_dout = 21; // GPIO 21 / phys 40



/*\\\ PROTECTED \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/

protected:



/*\\\ PRIVATE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/

private:



/*\\\ FORBIDDEN MEMBER FUNCTIONS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/

private:

GpioPin () = delete;
~GpioPin () = delete;
GpioPin (const GpioPin &other) = delete;
GpioPin (GpioPin &&other) = delete;
GpioPin & operator = (const GpioPin &other) = delete;
GpioPin & operator = (GpioPin &&other) = delete;
bool operator == (const GpioPin &other) const = delete;
bool operator != (const GpioPin &other) const = delete;

}; // class GpioPin



} // namespace hw
} // namespace mfx



//#include "mfx/hw/GpioPin.hpp"



#endif // mfx_hw_GpioPin_HEADER_INCLUDED



/*\\\ EOF \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
5 changes: 3 additions & 2 deletions src/mfx/hw/LedPi3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ To Public License, Version 2, as published by Sam Hocevar. See
/*\\\ INCLUDE FILES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/

#include "fstb/fnc.h"
#include "mfx/hw/GpioPin.h"
#include "mfx/hw/LedPi3.h"

#include <wiringPi.h>
Expand Down Expand Up @@ -53,9 +54,9 @@ namespace hw

const int LedPi3::_gpio_pin_arr [_nbr_led] =
#if defined (mfx_hw_LedPi3_REVERSE_ORDER)
{ 15, 13, 11 };
{ GpioPin::_led_2, GpioPin::_led_1, GpioPin::_led_0 };
#else
{ 11, 13, 15 };
{ GpioPin::_led_0, GpioPin::_led_1, GpioPin::_led_2 };
#endif


Expand Down
6 changes: 5 additions & 1 deletion src/mfx/hw/UserInputPi3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ To Public License, Version 2, as published by Sam Hocevar. See

/*\\\ INCLUDE FILES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/

#include "mfx/hw/GpioPin.h"
#include "mfx/hw/mcp23017.h"
#include "mfx/hw/UserInputPi3.h"
#include "mfx/ui/TimeShareThread.h"
Expand Down Expand Up @@ -72,7 +73,10 @@ const int UserInputPi3::_i2c_dev_23017_arr [_nbr_dev_23017] =
0x20 + 1
};

const int UserInputPi3::_gpio_pin_arr [_nbr_sw_gpio] = { 7, 22 };
const int UserInputPi3::_gpio_pin_arr [_nbr_sw_gpio] =
{
GpioPin::_nav_ok, GpioPin::_nav_cancel
};

const UserInputPi3::SwitchSrc UserInputPi3::_switch_arr [_nbr_switches] =
{
Expand Down
6 changes: 2 additions & 4 deletions src/mfx/ui/TimeShareThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ To Public License, Version 2, as published by Sam Hocevar. See
#include "mfx/ui/TimeShareCbInterface.h"
#include "mfx/ui/TimeShareThread.h"

#if fstb_SYS == fstb_SYS_LINUX
#include <wiringPi.h>
#elif fstb_SYS == fstb_SYS_WIN
#if fstb_SYS == fstb_SYS_WIN
#include <Windows.h>
#else
#elif fstb_SYS != fstb_SYS_LINUX
#error Unsupported system
#endif

Expand Down
Loading

0 comments on commit 129a1d8

Please sign in to comment.