uC/Matrix_Controller/Core/Src/matrix_util.c
void matr_get_baselevel(ADC_HandleTypeDef hadc){

	adc_complete = 0;							// reset value


	// loop over every column and get data
	for(int i = 0; i < N_COL; i++){

		// activate column
		matr_set_col_active(i);						// select column
		active_col = N_COL - 1;				// prevent ConvCpltCallback from starting a new conversion:
																	// trick into thinking this is the last conversion



		// do one full converion, store into base_data
		if(HAL_ADC_Start_DMA(&hadc, (uint32_t*)(base_level[i]), N_ROW) != HAL_OK){
			while(1);
			// failed to start adc
		}





		while(adc_complete == 0 && adc_error == 0)			// while not finished
			__asm("nop");								// do nothing

		if(adc_error){
			while(1);										// fuck
		}


		adc_complete = 0;							// reset value
	}
	adc_complete = 0;								// reset used variables


	// calculate threshold level according to a fixed value TRIGGER_LEVEL

	for(int i = 0; i < N_COL; i++){
		for(int j = 0; j < N_ROW; j++){

			threshold_level[i][j] = base_level[i][j] * TRIGGER_LEVEL;

		}
	}


}
/**
 * @brief Function to scan matrix to determine base light level of all elements
 * @param base_data: 2 dimensional vector for base level data of form uint8_t [COL][ROW]
 */
@brief Function to scan matrix to determine base light level of all elements
@param base_data: 2 dimensional vector for base level data of form uint8_t [COL][ROW]
@brief Function to scan matrix to determine base light level of all elements @param base_data : 2 dimensional vector for base level data of form uint8_t [ COL ] [ ROW ]
void matr_get_baselevel(ADC_HandleTypeDef hadc){
	adc_complete = 0;							
	for(int i = 0; i < N_COL; i++){
		matr_set_col_active(i);						
		active_col = N_COL - 1;				
		if(HAL_ADC_Start_DMA(&hadc, (uint32_t*)(base_level[i]), N_ROW) != HAL_OK){
			while(1);
		}
		while(adc_complete == 0 && adc_error == 0)			
			__asm("nop");								
		if(adc_error){
			while(1);										
		}
		adc_complete = 0;							
	}
	adc_complete = 0;								
	for(int i = 0; i < N_COL; i++){
		for(int j = 0; j < N_ROW; j++){
			threshold_level[i][j] = base_level[i][j] * TRIGGER_LEVEL;
		}
	}
}
void matr_get_baselevel ( ADC_HandleTypeDef hadc ) { adc_complete = 0 ; for ( int i = 0 ; i < N_COL ; i ++ ) { matr_set_col_active ( i ) ; active_col = N_COL - 1 ; if ( HAL_ADC_Start_DMA ( & hadc , ( uint32_t * ) ( base_level [ i ] ) , N_ROW ) != HAL_OK ) { while ( 1 ) ; } while ( adc_complete == 0 && adc_error == 0 ) __asm ( " " ) ; if ( adc_error ) { while ( 1 ) ; } adc_complete = 0 ; } adc_complete = 0 ; for ( int i = 0 ; i < N_COL ; i ++ ) { for ( int j = 0 ; j < N_ROW ; j ++ ) { threshold_level [ i ] [ j ] = base_level [ i ] [ j ] * TRIGGER_LEVEL ; } } }
@brief Function to scan matrix to determine base light level of all elements
 @param base_data: 2 dimensional vector for base level data of form uint8_t [COL][ROW]
@brief Function to scan matrix to determine base light level of all elements @param base_data : 2 dimensional vector for base level data of form uint8_t [ COL ] [ ROW ]
// reset value // loop over every column and get data // activate column // select column // prevent ConvCpltCallback from starting a new conversion: // trick into thinking this is the last conversion // do one full converion, store into base_data // failed to start adc // while not finished // do nothing // fuck // reset value // reset used variables // calculate threshold level according to a fixed value TRIGGER_LEVEL