Пример #1
0
int read_encoder(){
    int val = 0;
    
    //Set !OE low to enable output of encoder
    digitalWrite(OE, LOW);
    
    //Set SEL low to get high byte
    digitalWrite(SEL, LOW);
    
    //Wait about 20 microseconds
    _delay_us(20);
    
    //Read MSB
    val |= (reverse_byte(PINK) << 8);
    
    //Set SEL high to get low byte
    digitalWrite(SEL, HIGH);

    //Wait about 20 microseconds
    _delay_us(20);
    
    //Read LSB
    val |= reverse_byte(PINK);
    
    //Set !OE high to disable output of encoder
    digitalWrite(OE, HIGH);

    _delay_us(5);

    return val;
}
Пример #2
0
void load_key(char *key, char *iv, trivium_keystream *tks)
{
  int i;
  int KEY_BYTES = 10;

  /* We load the key in backwards using block_shift --- this
   * means we start at the end and copy in backwards, reversing
   * the bytes as we go. This complication is mostly due to the
   * fact that I decided to have the shift_registers outputting 
   * bytes oriented in the same way as an actual bytestring. */
  iv += KEY_BYTES - 1;
  key += KEY_BYTES - 1;
  
  /* Load the key and initialization vector into shift *
   * registers B and A respectively. */
  for (i = 0; i < KEY_BYTES; ++i, --iv, --key) {
    block_shift(tks->srA);
    block_shift(tks->srB);
    set_block_at(85, reverse_byte(*iv), tks->srA);
    set_block_at(76, reverse_byte(*key), tks->srB);
  }

  /* Set shift register C's bytes appropriately */
  set_block_at(0, 7, tks->srC);    
}
void framebuffer_x_y_mirror(void)
{
	uint16_t max = BYTES_PER_ROW*DISPLAY_HEIGHT;
	
	char temp;
	for(uint16_t i = 0 ; i < (max/2) ; i++){
		temp = current_framebuffer[i];
		current_framebuffer[i] = reverse_byte(current_framebuffer[max-1-i]);
		current_framebuffer[max-1-i] = reverse_byte(temp);
	}
	
}
Пример #4
0
/* write end command and crc command to memory. */
static void add_end_cmd(void)
{
	uint32_t crc32_pbl;
	int i;
	unsigned char *p = (unsigned char *)&pbl_end_cmd;

	if (ENDIANNESS == 'l') {
		for (i = 0; i < 4; i++)
			pbl_end_cmd[i] = reverse_byte(pbl_end_cmd[i]);
	}

	for (i = 0; i < 16; i++) {
		*pmem_buf++ = *p++;
		pbl_size++;
	}

	/* Add PBI CRC command. */
	*pmem_buf++ = 0x08;
	*pmem_buf++ = pbi_crc_cmd1;
	*pmem_buf++ = pbi_crc_cmd2;
	*pmem_buf++ = 0x40;
	pbl_size += 4;

	/* calculated CRC32 and write it to memory. */
	crc32_pbl = pbl_crc32(0, (const char *)mem_buf, pbl_size);
	*pmem_buf++ = (crc32_pbl >> 24) & 0xff;
	*pmem_buf++ = (crc32_pbl >> 16) & 0xff;
	*pmem_buf++ = (crc32_pbl >> 8) & 0xff;
	*pmem_buf++ = (crc32_pbl) & 0xff;
	pbl_size += 4;
}
Пример #5
0
int main()
{
    printf("// auto-generated file (do not edit)\n");
    printf("\n");
    printf("// reverse byte table\n");
    printf("unsigned const char liquid_reverse_byte[256] = {\n    ");
    unsigned int i;
    for (i=0; i<256; i++) {
        // reverse byte
        unsigned char byte_rev = reverse_byte((unsigned char)i);

        // print results
        printf("0x%.2x", byte_rev);

        if ( i != 255 ) {
            printf(",");
            if ( ((i+1)%8)==0 )
                printf("\n    ");
            else
                printf(" ");
        }

    }
    printf("};\n\n");
    
    return 0;
}
Пример #6
0
static int pblimage_verify_header(unsigned char *ptr, int image_size,
			struct image_tool_params *params)
{
	struct pbl_header *pbl_hdr = (struct pbl_header *) ptr;

	/* Only a few checks can be done: search for magic numbers */
	if (ENDIANNESS == 'l') {
		if (pbl_hdr->preamble != reverse_byte(RCW_PREAMBLE))
			return -FDT_ERR_BADSTRUCTURE;

		if (pbl_hdr->rcwheader != reverse_byte(RCW_HEADER))
			return -FDT_ERR_BADSTRUCTURE;
	} else {
		if (pbl_hdr->preamble != RCW_PREAMBLE)
			return -FDT_ERR_BADSTRUCTURE;

		if (pbl_hdr->rcwheader != RCW_HEADER)
			return -FDT_ERR_BADSTRUCTURE;
	}
	return 0;
}
Пример #7
0
void dogm_transfer_page(unsigned char from, unsigned char to){
  unsigned char column_adr;
 
  // Set write position
  dogm_cmd_mode();   
  dogm_spi_enable();
  #ifdef LCD_UPSIDE_DOWN
    dogm_spi_out(0xb0 | (7-dogm_current_page) );		// select current page
    
    // Leave 4 bits outside as the ST756R RAM is 132bits wide, not 128.
    // Note that if LCD_UPSIDE_DOWN is defined, ADC (column direction) is reversed
    column_adr = from+4;
  #else 
    dogm_spi_out(0xb0 | dogm_current_page );		// select current page
    column_adr = from;    
  #endif

  dogm_spi_out(0x10 | ((0xF0 & column_adr) >> 4));		// set upper 4 bit of the col adr to 0 
  dogm_spi_out(0x00 | ((0x0F & column_adr)     ));		// set lower 4 bit of the col adr to 0 
    
  dogm_spi_disable();
  
  // Send a complete page 
  dogm_data_mode();
  dogm_spi_enable();
  
  #ifdef LCD_UPSIDE_DOWN
  
  unsigned char idx;
  idx = from;
  while( idx <= to )
  {
    dogm_spi_out(dogm_page_buffer[idx]);    
    idx++;
  }
  #else
  
  unsigned char idx;
  idx = from;
  while( idx <= to )
  {
    // All fonts are upside down (MSB is on top)
    dogm_spi_out(reverse_byte(dogm_page_buffer[idx])); 
    idx++;
  }
  #endif
  
  dogm_spi_disable();
}
Пример #8
0
void sd_spi_transmit_byte(unsigned char byte)
{
    unsigned char c;

    /* reverse the bits before we busywait */
    byte = reverse_byte(byte);

    /* wait for any current transmit operation to complete */
    do{
        c = CSIO_CNTR;
    }while(c & CSIO_CNTR_TE);

    /* write the byte and enable transmitter */
    CSIO_TRDR = byte;
    CSIO_CNTR = c | CSIO_CNTR_TE;
}
Пример #9
0
uint8_t sd_spi_receive_byte(void)
{
    unsigned char c;

    /* wait for any current transmit or receive operation to complete */
    do{
        c = CSIO_CNTR;
    }while(c & (CSIO_CNTR_TE | CSIO_CNTR_RE));

    /* enable receive operation */
    CSIO_CNTR = c | CSIO_CNTR_RE;

    /* wait for receive to complete */
    while(CSIO_CNTR & CSIO_CNTR_RE);

    /* read byte */
    return reverse_byte(CSIO_TRDR);
}
Пример #10
0
void Display_Image(char image[])
{
	static unsigned char line_no;
	static unsigned int pixel;
	
	mraa_gpio_write(SCS, 1); //Select SHARP Display
	mraa_spi_write(spi, MLCD_WR); //Send Write Command	
	
	if(strcmp(image, "Uni_Freiburg") == 0)
	{
		for(line_no = 1; line_no <= MLCD_YRES; line_no++)
		{
			mraa_spi_write(spi, reverse_byte(line_no)); //Send Line Number
			
        		for(pixel = ((line_no - 1) * MLCD_BYTES); pixel < (line_no * MLCD_BYTES); pixel++)
        		{
				mraa_spi_write(spi, BMP_Uni_Freiburg[pixel]); //Send Data
        		}
	
		mraa_spi_write(spi, MLCD_TR); //Send Trailer
		}
	}

	else if(strcmp(image, "Intel_Atom") == 0)
	{
		for(line_no = 1; line_no <= MLCD_YRES; line_no++)
		{
			mraa_spi_write(spi, reverse_byte(line_no)); //Send Line Number
			
        		for(pixel = ((line_no - 1) * MLCD_BYTES); pixel < (line_no * MLCD_BYTES); pixel++)
        		{
				mraa_spi_write(spi, BMP_Intel_Atom[pixel]); //Send Data
        		}
	
		mraa_spi_write(spi, MLCD_TR); //Send Trailer
		}
	}

	else if(strcmp(image, "Nikola_Tesla") == 0)
	{
		for(line_no = 1; line_no <= MLCD_YRES; line_no++)
		{
			mraa_spi_write(spi, reverse_byte(line_no)); //Send Line Number
			
        		for(pixel = ((line_no - 1) * MLCD_BYTES); pixel < (line_no * MLCD_BYTES); pixel++)
        		{
				mraa_spi_write(spi, BMP_Nikola_Tesla[pixel]); //Send Data
        		}
	
		mraa_spi_write(spi, MLCD_TR); //Send Trailer
		}
	}

	else if(strcmp(image, "Albert_Einstein") == 0)
	{
		for(line_no = 1; line_no <= MLCD_YRES; line_no++)
		{
			mraa_spi_write(spi, reverse_byte(line_no)); //Send Line Number
			
        		for(pixel = ((line_no - 1) * MLCD_BYTES); pixel < (line_no * MLCD_BYTES); pixel++)
        		{
				mraa_spi_write(spi, BMP_Albert_Einstein[pixel]); //Send Data
        		}
	
		mraa_spi_write(spi, MLCD_TR); //Send Trailer
		}
	}

	else if(strcmp(image, "White_Tiger") == 0)
	{
		for(line_no = 1; line_no <= MLCD_YRES; line_no++)
		{
			mraa_spi_write(spi, reverse_byte(line_no)); //Send Line Number
			
        		for(pixel = ((line_no - 1) * MLCD_BYTES); pixel < (line_no * MLCD_BYTES); pixel++)
        		{
				mraa_spi_write(spi, BMP_White_Tiger[pixel]); //Send Data
        		}
	
		mraa_spi_write(spi, MLCD_TR); //Send Trailer
		}
	}

	else if(strcmp(image, "Wall_E") == 0)
	{
		for(line_no = 1; line_no <= MLCD_YRES; line_no++)
		{
			mraa_spi_write(spi, reverse_byte(line_no)); //Send Line Number
			
        		for(pixel = ((line_no - 1) * MLCD_BYTES); pixel < (line_no * MLCD_BYTES); pixel++)
        		{
				mraa_spi_write(spi, BMP_Wall_E[pixel]); //Send Data
        		}
	
		mraa_spi_write(spi, MLCD_TR); //Send Trailer
		}
	}
	
	mraa_spi_write(spi, MLCD_TR); //Send last Trailer
	mraa_gpio_write(SCS, 0); //Deselect SHARP Display
}