EihiS

June 13, 2014

Pi 3D reference files ( GLSL language, example shaders )

Filed under: Raspberry 3.14 — Tags: , , , , — admin @ 8:39 am

The files listed here are hosted on eihis.com’s website.
Reference for openGL ES 2.0 shader language aka ‘GLSL’ on the raspberry PI :

GL_shader_language_specifications_1-0-17 ( language specifications for OPENGL ES 2.0  )

Using this specifications, the ‘vertex’ and ‘fragment’ shader programs starts with preprocessor directive:

#version 100

Example vertex shader program using this specification’s syntax and types :

#version 100
attribute vec4 vPosition;
uniform mat4 viewMatrix, projMatrix,modelMatrix;
varying vec4 tcoord;
varying vec4 my_norm;
uniform float Scale;
void main(void)
{
lowp vec4 my_vector,my_test;
my_test=vPosition;
/* */
gl_Position = projMatrix * viewMatrix * modelMatrix * vPosition ;
my_vector=modelMatrix * vPosition;
my_norm=normalize(my_vector);
tcoord.x=my_norm.x;
tcoord.y=0.5;
tcoord.z=Scale;
}

Example fragment shader program, to be linked with the vertex’s one :

#version 100
precision mediump float;
varying vec4 tcoord;
/*out vec4 vOUTFragColor;*/
void main()
{
gl_FragColor = vec4(tcoord.x, tcoord.y , tcoord.z, 1.0);
}

Raspberry PI OpenGL es extensions :

GL_EXT_blend_minmax
GL_EXT_multi_draw_arrays
GL_EXT_texture_format_BGRA8888
GL_OES_compressed_ETC1_RGB8_texture
GL_OES_depth24
GL_OES_element_index_uint
GL_OES_fbo_render_mipmap
GL_OES_mapbuffer
GL_OES_rgb8_rgba8
GL_OES_standard_derivatives
GL_OES_stencil8
GL_OES_texture_3D
GL_OES_texture_npot
GL_OES_EGL_image
GL_OES_depth_texture
GL_OES_packed_depth_stencil
GL_EXT_texture_type_2_10_10_10_REV
GL_OES_get_program_binary
GL_APPLE_texture_max_level
GL_EXT_discard_framebuffer
GL_EXT_read_format_bgra
GL_NV_fbo_color_attachments
GL_OES_EGL_image_external
GL_OES_vertex_array_object
GL_EXT_texture_rg
GL_EXT_unpack_subimage
GL_NV_draw_buffers
GL_NV_read_buffer
GL_EXT_map_buffer_range
GL_OES_depth_texture_cube_map
GL_OES_surfaceless_context
GL_EXT_color_buffer_float

OpenGL ES 2.0 is very close to the CORE profile of OpenGL.
Forget about all built-in commands of the COMPATIBILITY profiles…

The Quick reference card for OPENGL ES 2.0 is here :  opengl-es-2_0-reference-card

You can also check this usefull link(s) :
http://en.wikibooks.org/wiki/GLSL_Programming/Vector_and_Matrix_Operations

314159265358979323846264338327950288
419716939937510582097494459230781640
628620899862803482534211706798214808

August 27, 2013

A simple SPI schematic, using MCP23S17 I/O expander

Filed under: Raspberry 3.14 — Tags: , , , , , , , , , , — admin @ 12:37 pm

Once SPI enabled in Raspbian, here is a simple test wiring, using microchip’s MCP23S17  I/O spi/I2C expander.
The chip is powered by the Pi’s 3.3V supply.
Explanation about the wiring is not really needed, as the schematic is pretty straightsimple.

A dip switches section is used to configure the mcp23s17’s SPI adress if needed (3bit) and another dip is used to have a hard-reset button if things are going bad.

One can test the circuit by using, or example, PORTB as output, and wiring leds+ a 220Ohm resistor to the ground, to get a visual feedback of the PORT’s output state.Thats what i did..

Now, after a carefull read of the MCP chip datasheet, one can properly program the registers of the chip to use it.
for our test purposes, i’ll state that we use PORTB as output.

Compile on the Pi that code
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <linux/types.h>
#include <linux/spi/spidev.h>

#include <sys/ioctl.h>
const unsigned char init_mcp_mode[]={ 0×40,0×0a,0×20 }; // no auto-inc, et bank=0
const unsigned char init_mcp_trisb[]={ 0×40,0×01,0×00 }; // as output
int main(int argc, char *argv[])
{
int fd_spi;
unsigned char to_send[4];

int value;
unsigned char byte;

unsigned int speed = 250000;

if (argc != 3) {
fprintf(stderr, "usage: %s <spi-port> <spi-speed>n", argv[0]);
exit(EXIT_FAILURE);
}
fd_spi = open(argv[1], O_RDWR);
if (fd_spi < 0) {
perror(argv[1]);
exit(EXIT_FAILURE);
}

if (sscanf(argv[2], “%d”, & speed) != 1) {
fprintf(stderr, “Wrong value for speed: %sn”, argv[2]);
exit(EXIT_FAILURE);
}
if (ioctl(fd_spi, SPI_IOC_WR_MAX_SPEED_HZ, & speed) != 0) {
perror(”ioctl”);
exit(EXIT_FAILURE);
}
// setup mcp
printf(”Setup:\n”);
printf(”Mode …[%d]\n”,write(fd_spi,&init_mcp_mode,3 ));
printf(”TrisB…[%d]\n”,write(fd_spi,&init_mcp_trisb,3));
//

byte=0;
while(1)  // forever loop, byte increments
{
byte ++;
to_send[0]=0×40;
to_send[1]=0×15; // reg=latB
to_send[2]=byte;
to_send[3]=0; // unused
if (write(fd_spi, &to_send, 3) != 3) {
perror(”write DATA”);
exit(EXIT_FAILURE);
}
usleep(25000); // 26ms sleep
}
close(fd_spi);
return EXIT_SUCCESS;
}

Run the file :

$ ./mcp_roller /dev/spidev0.0 400000

If you have connected leds+resistors to the PORTB of the mcp23s17, you should see it binary couting, visually.

Briefly, as for the code, mcp is first initialized with bank=0, no auto-increment feature, by the sequence :
0×40 = 01000000 == 0100 (fixed) + 000 (chip addr) + 0 (=write). (nb : the code example does not use the SPI chip addressing feature )
0×0A = register 0Ah == IOCON register addr
0×20 = 0b00100000 == bank0, SEQOP = OFF

then , code sets up Direction of port B :
0×40,0×01,0×00 : register 01h , all outputs (00h)

then , the program loops in sending portB latch register (15h) values, from 0 to FFh.
Writing to the latch of Port B is : 0×40,0×15,value.

Large parts of this code comes from : http://www.blaess.fr/christophe/2012/11/02/spi-sur-raspberry-pi-1/

314159265358979323846264338327950288
419716939937510582097494459230781640
628620899862803482534211706798214808

August 26, 2013

How-to activate the Pi SPI interface for 3.6.11+ kernel

Filed under: Raspberry 3.14 — Tags: , , , , , , — admin @ 10:41 am

Raspbian linux 3.6.11+ does not have SPI enabled by default.
the SPI is blacklisted in /etc/modprobe.d/raspi-blacklist.conf

Edit and comment (#) the SPI section in the file. Save and reboot.

Now, the SPI is listed when doing :

$ ls /dev/sp*

as /dev/spidev0.0 and /dev/spidev0.1 , wich are the 2 spi interfaces linked to the GPIO port ‘SS0 , SS1′ slave SPI “select” outputs.

Enjoy !

314159265358979323846264338327950288
419716939937510582097494459230781640
628620899862803482534211706798214808

cat{ } { post_456 } { } 2009-2015 EIhIS Powered by WordPress