diff options
Diffstat (limited to '2.3-1/macros/Hardware/RasberryPi/I2C')
11 files changed, 391 insertions, 0 deletions
diff --git a/2.3-1/macros/Hardware/RasberryPi/I2C/RPI_I2CRead.sci b/2.3-1/macros/Hardware/RasberryPi/I2C/RPI_I2CRead.sci new file mode 100755 index 00000000..afd98500 --- /dev/null +++ b/2.3-1/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/2.3-1/macros/Hardware/RasberryPi/I2C/RPI_I2CReadReg16.sci b/2.3-1/macros/Hardware/RasberryPi/I2C/RPI_I2CReadReg16.sci new file mode 100755 index 00000000..f0ad9898 --- /dev/null +++ b/2.3-1/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/2.3-1/macros/Hardware/RasberryPi/I2C/RPI_I2CReadReg8.sci b/2.3-1/macros/Hardware/RasberryPi/I2C/RPI_I2CReadReg8.sci new file mode 100755 index 00000000..d2ab59fd --- /dev/null +++ b/2.3-1/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/2.3-1/macros/Hardware/RasberryPi/I2C/RPI_I2CSetup.sci b/2.3-1/macros/Hardware/RasberryPi/I2C/RPI_I2CSetup.sci new file mode 100755 index 00000000..801c2e6d --- /dev/null +++ b/2.3-1/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/2.3-1/macros/Hardware/RasberryPi/I2C/RPI_I2CSetupInterface.sci b/2.3-1/macros/Hardware/RasberryPi/I2C/RPI_I2CSetupInterface.sci new file mode 100755 index 00000000..fed4f059 --- /dev/null +++ b/2.3-1/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/2.3-1/macros/Hardware/RasberryPi/I2C/RPI_I2CWrite.sci b/2.3-1/macros/Hardware/RasberryPi/I2C/RPI_I2CWrite.sci new file mode 100755 index 00000000..854b3b26 --- /dev/null +++ b/2.3-1/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/2.3-1/macros/Hardware/RasberryPi/I2C/RPI_I2CWriteReg16.sci b/2.3-1/macros/Hardware/RasberryPi/I2C/RPI_I2CWriteReg16.sci new file mode 100755 index 00000000..b2e8fb69 --- /dev/null +++ b/2.3-1/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/2.3-1/macros/Hardware/RasberryPi/I2C/RPI_I2CWriteReg8.sci b/2.3-1/macros/Hardware/RasberryPi/I2C/RPI_I2CWriteReg8.sci new file mode 100755 index 00000000..19c81570 --- /dev/null +++ b/2.3-1/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/2.3-1/macros/Hardware/RasberryPi/I2C/RPI_i2cdetect.sci b/2.3-1/macros/Hardware/RasberryPi/I2C/RPI_i2cdetect.sci new file mode 100755 index 00000000..a37bc4cb --- /dev/null +++ b/2.3-1/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/2.3-1/macros/Hardware/RasberryPi/I2C/buildmacros.sce b/2.3-1/macros/Hardware/RasberryPi/I2C/buildmacros.sce new file mode 100755 index 00000000..7d533f7b --- /dev/null +++ b/2.3-1/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/2.3-1/macros/Hardware/RasberryPi/I2C/names b/2.3-1/macros/Hardware/RasberryPi/I2C/names new file mode 100755 index 00000000..5a318865 --- /dev/null +++ b/2.3-1/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 |