summaryrefslogtreecommitdiff
path: root/macros/Hardware/RasberryPi/I2C
diff options
context:
space:
mode:
authorJorawar Singh2017-07-16 22:17:43 +0530
committerJorawar Singh2017-07-16 22:36:51 +0530
commitd9d92203ea349d5eb44c0edc5565d827322caabe (patch)
tree9bf874443e6e5a8ccd8fba3f5918297d95a194e8 /macros/Hardware/RasberryPi/I2C
parentce5c0f9d407d533364e9e7adc81e4d338e031383 (diff)
downloadScilab2C_fossee_old-d9d92203ea349d5eb44c0edc5565d827322caabe.tar.gz
Scilab2C_fossee_old-d9d92203ea349d5eb44c0edc5565d827322caabe.tar.bz2
Scilab2C_fossee_old-d9d92203ea349d5eb44c0edc5565d827322caabe.zip
Toolbox merge, RPI demos and structured demos
Diffstat (limited to 'macros/Hardware/RasberryPi/I2C')
-rwxr-xr-xmacros/Hardware/RasberryPi/I2C/RPI_I2CRead.sci40
-rwxr-xr-xmacros/Hardware/RasberryPi/I2C/RPI_I2CReadReg16.sci41
-rwxr-xr-xmacros/Hardware/RasberryPi/I2C/RPI_I2CReadReg8.sci41
-rwxr-xr-xmacros/Hardware/RasberryPi/I2C/RPI_I2CSetup.sci42
-rwxr-xr-xmacros/Hardware/RasberryPi/I2C/RPI_I2CSetupInterface.sci41
-rwxr-xr-xmacros/Hardware/RasberryPi/I2C/RPI_I2CWrite.sci41
-rwxr-xr-xmacros/Hardware/RasberryPi/I2C/RPI_I2CWriteReg16.sci42
-rwxr-xr-xmacros/Hardware/RasberryPi/I2C/RPI_I2CWriteReg8.sci42
-rwxr-xr-xmacros/Hardware/RasberryPi/I2C/RPI_i2cdetect.sci38
-rwxr-xr-xmacros/Hardware/RasberryPi/I2C/buildmacros.sce14
-rwxr-xr-xmacros/Hardware/RasberryPi/I2C/names9
11 files changed, 391 insertions, 0 deletions
diff --git a/macros/Hardware/RasberryPi/I2C/RPI_I2CRead.sci b/macros/Hardware/RasberryPi/I2C/RPI_I2CRead.sci
new file mode 100755
index 0000000..afd9850
--- /dev/null
+++ b/macros/Hardware/RasberryPi/I2C/RPI_I2CRead.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_I2CRead(fd)
+// Function to read device
+//
+// Calling Sequence
+// RPI_I2CRead(fd)
+//
+// Parameters
+// fd: file descriptor obtained from RPI_I2CSetup
+//
+// Description
+// Function for a simple device read. Some devices present data when you read them without having to do any register transactions.
+//
+// Examples
+// RPI_I2CRead(13)
+// See also
+// RPI_i2cdetect, RPI_I2CReadReg8, RPI_I2CReadReg16, RPI_I2CWrite, RPI_I2CWriteReg8, RPI_I2CWriteReg16, RPI_I2CSetupInterface, RPI_I2CSetup
+//
+// Authors
+// Jorawar Singh
+//
+// Bibliography
+// http://wiringpi.com/reference/
+
+ commande="CR1#1#"+string(fd)+"#";
+ 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/I2C/RPI_I2CReadReg16.sci b/macros/Hardware/RasberryPi/I2C/RPI_I2CReadReg16.sci
new file mode 100755
index 0000000..f0ad989
--- /dev/null
+++ b/macros/Hardware/RasberryPi/I2C/RPI_I2CReadReg16.sci
@@ -0,0 +1,41 @@
+// 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_I2CReadReg16(fd,reg)
+// Function to read 16-bit valu from the register
+//
+// Calling Sequence
+// RPI_I2CReadReg16(fd,reg)
+//
+// Parameters
+// fd : file descriptor obtained from RPI_I2CSetup
+// reg: integer register to read data from
+//
+// Description
+// This function reads a 16-bit value from the device register indicated.
+//
+// Examples
+// RPI_I2CReadReg16(13,0x40)
+// See also
+// RPI_i2cdetect, RPI_I2CRead, RPI_I2CReadReg8, RPI_I2CWrite, RPI_I2CWriteReg8, RPI_I2CWriteReg16, RPI_I2CSetupInterface, RPI_I2CSetup
+//
+// Authors
+// Jorawar Singh
+//
+// Bibliography
+// http://wiringpi.com/reference/
+
+ commande="CR3#2#"+string(fd)+"#"+string(reg)+"#";
+ 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/I2C/RPI_I2CReadReg8.sci b/macros/Hardware/RasberryPi/I2C/RPI_I2CReadReg8.sci
new file mode 100755
index 0000000..d2ab59f
--- /dev/null
+++ b/macros/Hardware/RasberryPi/I2C/RPI_I2CReadReg8.sci
@@ -0,0 +1,41 @@
+// 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_I2CReadReg8(fd,reg)
+// Function to read 8-bit valu from the register
+//
+// Calling Sequence
+// RPI_I2CReadReg8(fd,reg)
+//
+// Parameters
+// fd : file descriptor obtained from RPI_I2CSetup
+// reg: integer register to read data from
+//
+// Description
+// This function reads an 8-bit value from the device register indicated.
+//
+// Examples
+// RPI_I2CReadReg8(13,0x40)
+// See also
+// RPI_i2cdetect, RPI_I2CRead, RPI_I2CReadReg16, RPI_I2CWrite, RPI_I2CWriteReg8, RPI_I2CWriteReg16, RPI_I2CSetupInterface, RPI_I2CSetup
+//
+// Authors
+// Jorawar Singh
+//
+// Bibliography
+// http://wiringpi.com/reference/
+
+ commande="CR2#2#"+string(fd)+"#"+string(reg)+"#";
+ 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/I2C/RPI_I2CSetup.sci b/macros/Hardware/RasberryPi/I2C/RPI_I2CSetup.sci
new file mode 100755
index 0000000..801c2e6
--- /dev/null
+++ b/macros/Hardware/RasberryPi/I2C/RPI_I2CSetup.sci
@@ -0,0 +1,42 @@
+// 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_I2CSetup(addr)
+// Function to initialize the I2C system
+//
+// Calling Sequence
+// fd=RPI_I2CSetup(addr)
+//
+// Parameters
+// addr: integer, the I2C number of the device obtained using RPI_i2cdetect
+//
+// Description
+// This initialises the I2C system with your given device identifier. The addr is the I2C number of the device and obtained using RPI_i2cdetect program. The function works out the Raspberry Pi revision and opens the appropriate device in /dev.
+//
+//The return value is the standard Linux filehandle, or -1 if any error – in which case, errno can be consulted as usual.
+//
+// Examples
+// fd=RPI_I2CSetup(64)
+// See also
+// RPI_i2cdetect, RPI_I2CRead, RPI_I2CReadReg8, RPI_I2CReadReg16, RPI_I2CWrite, RPI_I2CWriteReg8, RPI_I2CWriteReg16, RPI_I2CSetupInterface
+//
+// Authors
+// Jorawar Singh
+//
+// Bibliography
+// http://wiringpi.com/reference/
+
+ commande="CSe#1#"+string(addr)+"#";
+ 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/I2C/RPI_I2CSetupInterface.sci b/macros/Hardware/RasberryPi/I2C/RPI_I2CSetupInterface.sci
new file mode 100755
index 0000000..fed4f05
--- /dev/null
+++ b/macros/Hardware/RasberryPi/I2C/RPI_I2CSetupInterface.sci
@@ -0,0 +1,41 @@
+// 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_I2CSetupInterface(device,addr)
+// Function to select different I2C interfaces
+//
+// Calling Sequence
+// I2CSetupInterface(device,addr)
+//
+// Parameters
+// device: device
+// addr : the I2C number of the device obtained using RPI_i2cdetect
+//
+// Description
+// This feature is not implemented currently, and will be used to select different I2C interfaces if the RPi ever receives them.
+//
+// Examples
+// I2CSetupInterface(1,0x48)
+// See also
+// RPI_i2cdetect, RPI_I2CRead, RPI_I2CReadReg8, RPI_I2CReadReg16, RPI_I2CWrite, RPI_I2CWriteReg8, RPI_I2CWriteReg16, RPI_I2CSetup
+//
+// Authors
+// Jorawar Singh
+//
+// Bibliography
+// http://wiringpi.com/reference/
+
+ commande="CSI#2#"+string(device)+"#"+string(addr)+"#";
+ 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/I2C/RPI_I2CWrite.sci b/macros/Hardware/RasberryPi/I2C/RPI_I2CWrite.sci
new file mode 100755
index 0000000..854b3b2
--- /dev/null
+++ b/macros/Hardware/RasberryPi/I2C/RPI_I2CWrite.sci
@@ -0,0 +1,41 @@
+// 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_I2CWrite(fd,data)
+// Function to write to device
+//
+// Calling Sequence
+// RPI_I2CWrite(fd,data)
+//
+// Parameters
+// fd : file descriptor obtained from RPI_I2CSetup
+// data: integer data to write to device
+//
+// Description
+// Function for simple device write. Some devices accept data this way without needing to access any internal registers.
+//
+// Examples
+// RPI_I2CWrite(13,100)
+// See also
+// RPI_i2cdetect, RPI_I2CRead, RPI_I2CReadReg8, RPI_I2CReadReg16, RPI_I2CWriteReg8, RPI_I2CWriteReg16, RPI_I2CSetupInterface, RPI_I2CSetup
+//
+// Authors
+// Jorawar Singh
+//
+// Bibliography
+// http://wiringpi.com/reference/
+
+ commande="CW1#2#"+string(fd)+"#"+string(data)+"#";
+ 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/I2C/RPI_I2CWriteReg16.sci b/macros/Hardware/RasberryPi/I2C/RPI_I2CWriteReg16.sci
new file mode 100755
index 0000000..b2e8fb6
--- /dev/null
+++ b/macros/Hardware/RasberryPi/I2C/RPI_I2CWriteReg16.sci
@@ -0,0 +1,42 @@
+// 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_I2CWriteReg16(fd,reg,data)
+// Function to write 16-bit data to register
+//
+// Calling Sequence
+// RPI_I2CWriteReg16(fd,reg,data)
+//
+// Parameters
+// fd : file descriptor obtained from RPI_I2CSetup
+// reg : integer register to write data at
+// data: integer data to write to device
+//
+// Description
+// This function writes a 16-bit data value into the device register indicated.
+//
+// Examples
+// RPI_I2CWriteReg16(13,0x40,100)
+// See also
+// RPI_i2cdetect, RPI_I2CRead, RPI_I2CReadReg8, RPI_I2CReadReg16, RPI_I2CWrite, RPI_I2CWriteReg8, RPI_I2CSetupInterface, RPI_I2CSetup
+//
+// Authors
+// Jorawar Singh
+//
+// Bibliography
+// http://wiringpi.com/reference/
+
+ commande="CW3#3#"+string(fd)+"#"+string(reg)+"#"+string(data)+"#";
+ 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/I2C/RPI_I2CWriteReg8.sci b/macros/Hardware/RasberryPi/I2C/RPI_I2CWriteReg8.sci
new file mode 100755
index 0000000..19c8157
--- /dev/null
+++ b/macros/Hardware/RasberryPi/I2C/RPI_I2CWriteReg8.sci
@@ -0,0 +1,42 @@
+// 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_I2CWriteReg8(fd,reg,data)
+// Function to write 8-bit data to register
+//
+// Calling Sequence
+// RPI_I2CWriteReg8(fd,reg,data)
+//
+// Parameters
+// fd : file descriptor obtained from RPI_I2CSetup
+// reg : integer register to write data at
+// data: integer data to write to device
+//
+// Description
+// This function writes an 8-bit data value into the device register indicated.
+//
+// Examples
+// RPI_I2CWriteReg8(13,0x40,100)
+// See also
+// RPI_i2cdetect, RPI_I2CRead, RPI_I2CReadReg8, RPI_I2CReadReg16, RPI_I2CWrite, RPI_I2CWriteReg16, RPI_I2CSetupInterface, RPI_I2CSetup
+//
+// Authors
+// Jorawar Singh
+//
+// Bibliography
+// http://wiringpi.com/reference/
+
+ commande="CW2#3#"+string(fd)+"#"+string(reg)+"#"+string(data)+"#";
+ 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/I2C/RPI_i2cdetect.sci b/macros/Hardware/RasberryPi/I2C/RPI_i2cdetect.sci
new file mode 100755
index 0000000..a37bc4c
--- /dev/null
+++ b/macros/Hardware/RasberryPi/I2C/RPI_i2cdetect.sci
@@ -0,0 +1,38 @@
+// 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_i2cdetect()
+// Function to get the address of attached i2c device
+//
+// Calling Sequence
+// RPI_i2cdetect()
+//
+// Description
+// This function returns the address of the i2c device connected to the Raspberry pi.
+//
+// Examples
+// addr=RPI_i2cdetect()
+// See also
+// RPI_I2CRead, RPI_I2CSetup, RPI_I2CReadReg8, RPI_I2CReadReg16, RPI_I2CSetupInterface, RPI_I2CWrite, RPI_I2CWriteReg8, RPI_I2CWriteReg16
+//
+// Authors
+// Jorawar Singh
+//
+// Bibliography
+// http://wiringpi.com/reference/
+
+ rev=RPI_boardRev();
+ commande="i2c#1#i2cdetect -y "+string(strtod(rev)-1)+"#";
+ 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/I2C/buildmacros.sce b/macros/Hardware/RasberryPi/I2C/buildmacros.sce
new file mode 100755
index 0000000..7d533f7
--- /dev/null
+++ b/macros/Hardware/RasberryPi/I2C/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/I2C/names b/macros/Hardware/RasberryPi/I2C/names
new file mode 100755
index 0000000..5a31886
--- /dev/null
+++ b/macros/Hardware/RasberryPi/I2C/names
@@ -0,0 +1,9 @@
+RPI_I2CRead
+RPI_I2CReadReg16
+RPI_I2CReadReg8
+RPI_I2CSetup
+RPI_I2CSetupInterface
+RPI_I2CWrite
+RPI_I2CWriteReg16
+RPI_I2CWriteReg8
+RPI_i2cdetect