diff options
author | Abhinav Dronamraju | 2017-07-17 22:03:40 +0530 |
---|---|---|
committer | Abhinav Dronamraju | 2017-07-17 22:03:40 +0530 |
commit | 70ec68c70d86edcf17f3ab5aa74a4598d48c0fc8 (patch) | |
tree | 98467a7fccd87beca85bbd5b75123a96817356d3 /macros/Hardware/RasberryPi/Setup | |
parent | 574ddf08c208a2d1b8c27fe29525f631816c32d5 (diff) | |
parent | 51a8cdb8a204ff4327e2e734e78c2447a9bdd865 (diff) | |
download | Scilab2C_fossee_old-70ec68c70d86edcf17f3ab5aa74a4598d48c0fc8.tar.gz Scilab2C_fossee_old-70ec68c70d86edcf17f3ab5aa74a4598d48c0fc8.tar.bz2 Scilab2C_fossee_old-70ec68c70d86edcf17f3ab5aa74a4598d48c0fc8.zip |
Merged fossee master
Diffstat (limited to 'macros/Hardware/RasberryPi/Setup')
-rwxr-xr-x | macros/Hardware/RasberryPi/Setup/RPI_getAlt.sci | 40 | ||||
-rwxr-xr-x | macros/Hardware/RasberryPi/Setup/RPI_pinMode.sci | 60 | ||||
-rwxr-xr-x | macros/Hardware/RasberryPi/Setup/RPI_pinModeAlt.sci | 55 | ||||
-rwxr-xr-x | macros/Hardware/RasberryPi/Setup/RPI_pinNumbering.sci | 54 | ||||
-rwxr-xr-x | macros/Hardware/RasberryPi/Setup/RPI_pullControl.sci | 60 | ||||
-rwxr-xr-x | macros/Hardware/RasberryPi/Setup/buildmacros.sce | 14 | ||||
-rwxr-xr-x | macros/Hardware/RasberryPi/Setup/names | 5 |
7 files changed, 288 insertions, 0 deletions
diff --git a/macros/Hardware/RasberryPi/Setup/RPI_getAlt.sci b/macros/Hardware/RasberryPi/Setup/RPI_getAlt.sci new file mode 100755 index 0000000..ba3d204 --- /dev/null +++ b/macros/Hardware/RasberryPi/Setup/RPI_getAlt.sci @@ -0,0 +1,40 @@ +// Copyright (C) 2017 - IIT Bombay - FOSSEE +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + +function out=RPI_getAlt(pin) +// Function to get the current mode of pin +// +// Calling Sequence +// s=RPI_getAlt(pin) +// +// Parameters +// pin: The pin number to read the voltage from. Numbering sequence to be followed as initiated using RPI_pinNumbering function. +// +// Description +// This function returns the current mode of the pin. Output will be 0 for INPUT, 1 for OUTPUT, 2 for PWM_OUT and 3 for CLOCK. +// +// Examples +// s=RPI_getAlt(0) +// See also +// RPI_pinNumbering, RPI_pinModeAlt +// +// Authors +// Jorawar Singh +// +// Bibliography +// http://wiringpi.com/reference/ + + commande="gAt#1#"+string(pin)+"#"; + if getos()=="Linux" then + out=unix_g("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()"""); + elseif getos()=="Windows" then + [out,RPI_winR]=dos("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()"""); + end +endfunction diff --git a/macros/Hardware/RasberryPi/Setup/RPI_pinMode.sci b/macros/Hardware/RasberryPi/Setup/RPI_pinMode.sci new file mode 100755 index 0000000..b6f52e6 --- /dev/null +++ b/macros/Hardware/RasberryPi/Setup/RPI_pinMode.sci @@ -0,0 +1,60 @@ +// Copyright (C) 2017 - IIT Bombay - FOSSEE +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + + +function RPI_pinMode(pin,Mode) +// Function to set the mode of the given pin. +// +// Calling Sequence +// RPI_pinMode(pin,Mode) +// +// Parameters +// pin : The pin number to act on. Numbering sequence to be followed as initiated using RPI_pinNumbering function. +// Mode: The mode in which to set the pin. +// +// Description +// This function configures the Raspberry Pi's given pin to work as the given mode (input/output/pwm/clock). Not all functions are available to all the pins. +// +// Mode can take the following values- +// <itemizedlist> +// <listitem><para>'in' -> sets the pin as input</para></listitem> +// <listitem><para>'out' -> sets the pin as output</para></listitem> +// <listitem><para>'pwm' -> sets the pin to PWM output. Only wiringPi pin 1 (BCM_GPIO pin 18) supports this function.</para></listitem> +// <listitem><para>'clock' -> sets the pin to CLOCK output. Only wiringPi pin 7 (BCM_GPIO pin 4) supports this function.</para></listitem> +// </itemizedlist> +// +// Examples +// RPI_pinMode(0,'out') +// See also +// RPI_pinNumbering +// +// Authors +// Jorawar Singh +// +// Bibliography +// http://wiringpi.com/reference/ + + if Mode=='in' then + commande="pnM#2#"+string(pin)+"#0#"; + elseif Mode=='out' then + commande="pnM#2#"+string(pin)+"#1#"; + elseif Mode=='pwm' then + commande="pnM#2#"+string(pin)+"#2#"; + elseif Mode=='clock' then + commande="pnM#2#"+string(pin)+"#3#"; + else + error("Mode should be one of ""in/out/pwm/clock/soft_pwm/soft_tone/pwm_tone""."); + end + if getos=="Linux" then + unix_w("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()"""); + elseif getos=="Windows" then + RPI_winR=dos("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()"""); + end +endfunction diff --git a/macros/Hardware/RasberryPi/Setup/RPI_pinModeAlt.sci b/macros/Hardware/RasberryPi/Setup/RPI_pinModeAlt.sci new file mode 100755 index 0000000..dd0fa10 --- /dev/null +++ b/macros/Hardware/RasberryPi/Setup/RPI_pinModeAlt.sci @@ -0,0 +1,55 @@ +// Copyright (C) 2017 - IIT Bombay - FOSSEE +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + +function RPI_pinModeAlt(pin,ALTMode) +// Function to set the current mode of pin +// +// Calling Sequence +// RPI_pinModeAlt(pin,ALTMode) +// +// Parameters +// pin : The pin number to read the voltage from. Numbering sequence to be followed as initiated using RPI_pinNumbering function. +// ALTMode: integer, from 0 to 7 +// +// Description +// This function sets the mode of the pin to either of the general GPIO (also set through RPI_pinMode function) or the alternatives available (not accessible through RPI_pinMode function). +// +// ALTMode can take the following values: +// <itemizedlist> +// <listitem>0 : Input</listitem> +// <listitem>1 : Output</listitem> +// <listitem>2 : ALT5</listitem> +// <listitem>3 : ALT4</listitem> +// <listitem>4 : ALT0</listitem> +// <listitem>5 : ALT1</listitem> +// <listitem>6 : ALT2</listitem> +// <listitem>7 : ALT3</listitem> +// </itemizedlist> +// +//The list of Alternate functions of all the pins can be found on page 102 of the official documentation: https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf +// +// Examples +// RPI_pinModeAlt(1,2) +// See also +// RPI_pinMode, RPI_pinNumbering, RPI_getAlt +// +// Authors +// Jorawar Singh +// +// Bibliography +// http://wiringpi.com/reference/ + + commande="pMA#2#"+string(pin)+"#"+string(ALTMode)+"#"; + if getos()=="Linux" then + unix_w("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()"""); + elseif getos()=="Windows" then + RPI_winR=dos("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()"""); + end +endfunction diff --git a/macros/Hardware/RasberryPi/Setup/RPI_pinNumbering.sci b/macros/Hardware/RasberryPi/Setup/RPI_pinNumbering.sci new file mode 100755 index 0000000..4716de8 --- /dev/null +++ b/macros/Hardware/RasberryPi/Setup/RPI_pinNumbering.sci @@ -0,0 +1,54 @@ +// Copyright (C) 2017 - IIT Bombay - FOSSEE +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + +function out=RPI_pinNumbering(pinSetup) +// Function to initialize wiringpi with the number sequence to be followed. +// +// Calling Sequence +// RPI_pinNumbering(pinSetup) +// +// Parameters +// pinSetup: The pin number sequence to follow +// +// Description +// This function must be called at the start of the program or the program will fail to work correctly. It tells the wiringpi which number sequence will be used to work on Raspberry Pi. Returns 0 if no errors encountered. Pin maps for the different pinSetups can be found at the link in bibliography. +// +// pinSetup can take the following values: +// <itemizedlist> +// <listitem>'wiringpi' -> This initialises wiringPi and assumes that the calling program is going to be using the wiringPi pin numbering scheme. This is a simplified numbering scheme which provides a mapping from virtual pin numbers to the real underlying Broadcom GPIO pin numbers.</listitem> +// <listitem>'GPIO' -> Same as above, however it allows the calling programs to use the Broadcom GPIO pin numbers directly with no re-mapping.</listitem> +// <listitem>'phys' -> Identical to above, however it allows the calling programs to use the physical pin numbers on the P1 connector only.</listitem> +// </itemizedlist> +// +// Examples +// RPI_pinNumbering('wiringpi') +// Authors +// Jorawar Singh +// +// Bibliography +// http://wiringpi.com/reference/ + + if (pinSetup=='wiringpi') then + commande="pN0#0#"; + elseif (pinSetup=='GPIO') then + commande="pN1#0#"; + elseif (pinSetup=='sys') then + commande="pN2#0#"; + elseif (pinSetup=='phys') then + commande="pN3#0#"; + else + error("pinSetup should be one of wiringpi/GPIO/sys/phys"); + end + if getos()=="Linux" then + out=unix_g("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()"""); + elseif getos()=="Windows" then + [out,RPI_winR]=dos("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()"""); + end +endfunction diff --git a/macros/Hardware/RasberryPi/Setup/RPI_pullControl.sci b/macros/Hardware/RasberryPi/Setup/RPI_pullControl.sci new file mode 100755 index 0000000..6354bf5 --- /dev/null +++ b/macros/Hardware/RasberryPi/Setup/RPI_pullControl.sci @@ -0,0 +1,60 @@ +// Copyright (C) 2017 - IIT Bombay - FOSSEE +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + +function RPI_pullControl(pin,RMode) +// Function to change the internal pull up/down resistor setting for a given pin. +// +// Calling Sequence +// RPI_pullControl(pin,RMode) +// +// Parameters +// pin : The pin number to act on. Numbering sequence to be followed as initiated using RPI_pinNumbering function. +// RMode: The mode for the internal resistance of the given pin. +// +// Description +// This sets the pull-up or pull-down resistor mode on the given pin, which should be set as an input using the PRI_pinMode function. The internal pull up/down +// resistors have a value of approximately 50KΩ on the Raspberry Pi. +// +// RMode can take values: +// <itemizedlist> +// <listitem>'up' -> pull to 3.3v</listitem> +// <listitem>'down'-> pull to ground</listitem> +// <listitem>'none'-> no pull up/down</listitem> +// </itemizedlist> +// +// This function has no effect on the Raspberry Pi’s GPIO pins when in sys mode, set using RPI_pinNumbering function. To activate a pull-up/pull-down, use the gpio +// program in a script before starting the program. +// +// Examples +// RPI_pullControl(0,'down') +// See also +// RPI_pinNumbering, RPI_pinMode +// +// Authors +// Jorawar Singh +// +// Bibliography +// http://wiringpi.com/reference/ + + if RMode=='up' then + commande="plC#2#"+string(pin)+"#2#"; + elseif RMode=='down' then + commande="plC#2#"+string(pin)+"#1#"; + elseif RMode=='none' then + commande="plC#2#"+string(pin)+"#0#"; + else + error("mode should be one of up/down/none"); + end + if getos()=="Linux" then + unix_w("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()"""); + elseif getos()=="Windows" then + RPI_winR=dos("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()"""); + end +endfunction diff --git a/macros/Hardware/RasberryPi/Setup/buildmacros.sce b/macros/Hardware/RasberryPi/Setup/buildmacros.sce new file mode 100755 index 0000000..7d533f7 --- /dev/null +++ b/macros/Hardware/RasberryPi/Setup/buildmacros.sce @@ -0,0 +1,14 @@ +// Copyright (C) 2017 - IIT Bombay - FOSSEE +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// Author: Jorawar Singh +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + +tbx_build_macros(TOOLBOX_NAME, get_absolute_file_path('buildmacros.sce')); + +clear tbx_build_macros; diff --git a/macros/Hardware/RasberryPi/Setup/names b/macros/Hardware/RasberryPi/Setup/names new file mode 100755 index 0000000..3895498 --- /dev/null +++ b/macros/Hardware/RasberryPi/Setup/names @@ -0,0 +1,5 @@ +RPI_getAlt +RPI_pinMode +RPI_pinModeAlt +RPI_pinNumbering +RPI_pullControl |