Example #1
0
void	writeStrip(pixel_t strip[], uint8_t stripLen, void (*spi_write_p)(uint8_t)) {
	uint8_t	j;
	for (j=0; j<stripLen; j++) {
		spi_write_p(strip[j].g);
		spi_write_p(strip[j].r);
		spi_write_p(strip[j].b);
	}
}
Example #2
0
void	latchStrip(void (*spi_write_p)(uint8_t), uint8_t stripLen ) {
	uint16_t n;
	n = ((stripLen+63)/64) * 3;

	while (n--) spi_write_p(0);
}
int16_t magneto_hal_write( uint16_t address, int16_t value )
{
    uint16_t command;

    switch( current_mode )
    {
        case MAGNETO_I2C:
        {
            uint8_t buffer[ AS5048A_MAX_READ_SIZE ];
            buffer[1] = ( uint8_t )value & 0xff;

            switch( address )
            {
                case AS5048A_CLEAR_ERROR_FLAG:

                    break;
                case AS5048A_PROGRAMMING_CONTROL:
                    buffer[0] = 0x03;
                    break;
                case AS5048A_OTP_REGISTER_ZERO_POS_HIGH:
                    buffer[0] = 0x16;
                    break;
                case AS5048A_OTP_REGISTER_ZERO_POS_LOW:
                    buffer[0] = 0x17;
                    break;
            }
#if defined( __MIKROC_PRO_FOR_ARM__ )
#if defined( STM32F107VC ) || defined( STM32F407VG ) || \
    defined( STM32F030C6 ) || defined( STM32F746VG )
            i2c_start_p();
            i2c_write_p( i2c_address,
                         buffer,
                         2,
                         END_MODE_STOP );
#elif defined( LM3S1165 ) || defined( TM4C129ENCZAD )
      i2c_set_slave_address_p( i2c_address, _I2C_DIR_MASTER_TRANSMIT );
      i2c_write_p( buffer[0], _I2C_MASTER_MODE_BURST_SEND_START );
      i2c_write_p( buffer[1], _I2C_MASTER_MODE_BURST_SEND_FINISH );
#endif
#elif defined(__MIKROC_PRO_FOR_FT90x__)
            i2c_set_slave_address_p( i2c_address );
            //TODO: Send bytes
            i2c_write_p( buffer[0] );
            i2c_write_p( buffer[1] );

#elif defined(__MIKROC_PRO_FOR_AVR__)   || \
  defined(__MIKROC_PRO_FOR_8051__)  || \
  defined(__MIKROC_PRO_FOR_DSPIC__) || \
  defined(__MIKROC_PRO_FOR_PIC32__) || \
  defined(__MIKROC_PRO_FOR_PIC__)
            i2c_start_p();
            i2c_write_p( i2c_address | WRITE );
            i2c_write_p( buffer[0] );
            i2c_write_p( buffer[1] );
            i2c_stop_p();

#elif defined( __GNUC__)
            printf( "Start\n" );
            printf( "Address: 0x%02x\n", address );
            printf( "\tData: 0x%02x\n", value );
#endif
        }
        break;
        case MAGNETO_SPI:

#if defined ( __GNUC__ )
            cs_low();
            printf( "%s\n", byte_to_binary( command ) ); // Write command
            cs_high();
            cs_low();
            printf( "%s\n", byte_to_binary( value ) );
            cs_high();
#else
            command = 0x00 | ( address & 0x3FFF );
            command |= ( ( int16_t )parity_check( command ) << AS5048A_PARITY_BIT );

            if( device_count == 1 )
            {
                cs_low();
                spi_write_p( ( command >> 8 ) & 0xff );
                spi_write_p( command & 0xff );
                cs_high();

                value = 0x00 | ( value & 0x3FFF );
                value |= ( ( int16_t )parity_check( value ) << AS5048A_PARITY_BIT );

                cs_low();
                spi_write_p( ( value >> 8 ) & 0xff );
                spi_write_p( value & 0xff );
                cs_high();

                cs_low();
                command = ( spi_read_p( 0x00 ) << 8 );
                command |= spi_read_p( 0x00 );
                cs_high();
            }
            else
            {