make led1642gw.c more generic
This commit is contained in:
		
							
								
								
									
										33
									
								
								led1642gw.c
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								led1642gw.c
									
									
									
									
									
								
							@@ -29,7 +29,7 @@
 | 
			
		||||
 * the data registers of the LED1642 ICs.
 | 
			
		||||
 */
 | 
			
		||||
static uint16_t ledbuffer[NUM_LED_CHANNELS];
 | 
			
		||||
 | 
			
		||||
static uint16_t config_reg[3];
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Write 16 bits of \data, with LE set high
 | 
			
		||||
@@ -75,6 +75,7 @@ static void write_data_latch(uint16_t data)
 | 
			
		||||
  write_data(data, 4);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/* 
 | 
			
		||||
 * Write data to BRIGHTNESS GLOBAL LATCH register.
 | 
			
		||||
 * that means setting LE high for 5 or 6 clock cycles
 | 
			
		||||
@@ -84,6 +85,7 @@ static void write_global_latch(uint16_t data)
 | 
			
		||||
  write_data(data, 6);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * This function shifts data through the 16bit shift
 | 
			
		||||
 * register of the LED1642GW, without writing the data
 | 
			
		||||
@@ -97,6 +99,20 @@ static void write_no_command(uint16_t data)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Write data to CONFIG register.
 | 
			
		||||
 * that means setting LE high for 7 clock cycles
 | 
			
		||||
 */
 | 
			
		||||
void led1642gw_flush_config(void)
 | 
			
		||||
{
 | 
			
		||||
  uint8_t ic;
 | 
			
		||||
  for (ic=0; ic<(NUM_LED1642GW_ICs-1); ic++) {
 | 
			
		||||
    write_no_command(config_reg[ic]);
 | 
			
		||||
  }
 | 
			
		||||
  write_data(config_reg[ic], 7);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/* 
 | 
			
		||||
 * Turn all channels on, so the data in the DATA LATCH 
 | 
			
		||||
 * register affects the LEDs attached to the IC.
 | 
			
		||||
@@ -104,8 +120,10 @@ static void write_no_command(uint16_t data)
 | 
			
		||||
void led1642gw_turn_all_on(void)
 | 
			
		||||
{
 | 
			
		||||
  
 | 
			
		||||
  write_data(0xffff, 2);
 | 
			
		||||
  write_data(0xffff, 2);
 | 
			
		||||
  uint8_t ic;
 | 
			
		||||
  for (ic=0; ic<(NUM_LED1642GW_ICs-1); ic++) {
 | 
			
		||||
    write_no_command(0xffff);
 | 
			
		||||
  }
 | 
			
		||||
  write_data(0xffff, 2);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -115,9 +133,10 @@ void led1642gw_turn_all_on(void)
 | 
			
		||||
 */
 | 
			
		||||
void led1642gw_turn_all_off(void)
 | 
			
		||||
{
 | 
			
		||||
  
 | 
			
		||||
  write_data(0x0000, 2);
 | 
			
		||||
  write_data(0x0000, 2);
 | 
			
		||||
  uint8_t ic;
 | 
			
		||||
  for (ic=0; ic<(NUM_LED1642GW_ICs-1); ic++) {
 | 
			
		||||
    write_no_command(0x0000);
 | 
			
		||||
  }
 | 
			
		||||
  write_data(0x0000, 2);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -137,6 +156,7 @@ void led1642gw_init(void)
 | 
			
		||||
  DDR_SDI |= (1<<PIN_SDI);
 | 
			
		||||
  DDR_LE |= (1<<PIN_LE);
 | 
			
		||||
  memset(ledbuffer, 0x00, sizeof(ledbuffer));
 | 
			
		||||
  memset(config_reg, 0x00, sizeof(config_reg));
 | 
			
		||||
  led1642gw_flush();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -196,3 +216,4 @@ void led1642gw_clear(void)
 | 
			
		||||
  memset(ledbuffer, 0x00, sizeof(ledbuffer));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user