main/main.c
void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
{
	switch(event) {
		case ESP_GATTS_REG_EVT:
			esp_ble_gap_set_device_name(DEVICE_NAME);

			dsp_profile_tab[DSP_PROFILE_APP_IDX].gatts_if = gatts_if;

			esp_ble_gatts_create_attr_tab(dsp_db, gatts_if, NUM_TABLE_ELEMENTS, SVC_INST_ID);

            esp_ble_gap_config_adv_data(&adv_data_config);
            esp_ble_gap_config_adv_data(&scan_rsp_data);
		break;
		case ESP_GATTS_CREATE_EVT:
			break;
		case ESP_GATTS_READ_EVT:
			break;
		case ESP_GATTS_WRITE_EVT:
			if(dsp_control_handle_table[IDX_CHAR_VOL_VAL] == param->write.handle){
				float newVol = *param->write.value;
				newVol = newVol/100;
				process_coefficient_for_i2c(newVol, DSP_VOLUME_LEVEL);
				SIGMA_SAFELOAD_SINGLE(0x34, VOL_PARAM_ADDR, DSP_VOLUME_LEVEL);


			} else if (dsp_control_handle_table[IDX_CHAR_Q_VAL] == param->write.handle){
				float newQ = *param->write.value;
				newQ = newQ/25;
				float *ptr = calculate_coefficients(low_pass, gain, newQ, cutFreq);
				SIGMA_SAFELOAD_BIQUAD(0x34, BIQUAD_PARAM_BASE_ADDR, ptr);

			} else if (dsp_control_handle_table[IDX_CHAR_CUTFREQ_VAL] == param->write.handle) {
				float newCutFreq = *param->write.value *10;
				printf("New cut-off frequency value: %f\n", newCutFreq);
				printf("Q: %f  |  newCutFreq: %f\n", Q, newCutFreq);
				float *ptr = calculate_coefficients(low_pass, gain, Q, newCutFreq);
			 	SIGMA_SAFELOAD_BIQUAD(0x34, BIQUAD_PARAM_BASE_ADDR, ptr);

			} else if (dsp_control_handle_table[IDX_CHAR_GAIN_VAL] == param->write.handle){
				float newGain = *param->write.value ;
				printf("New gain value: %f\n", gain);
				printf("Q: %f  |  newCutFreq: %f\n", Q, newGain);
				float *ptr = calculate_coefficients(low_pass, newGain, Q, cutFreq);
			 	SIGMA_SAFELOAD_BIQUAD(0x34, BIQUAD_PARAM_BASE_ADDR, ptr);
			}


			break;
		case ESP_GATTS_EXEC_WRITE_EVT:
			break;
		case ESP_GATTS_CONF_EVT:
			break;
		case ESP_GATTS_MTU_EVT:
			break;
		case ESP_GATTS_START_EVT:
			break;
		case ESP_GATTS_CONNECT_EVT:
			printf("gatts_profile_event_handler: ");
					printf("ESP_GATTS_CONNECT_EVT called.\n");
		            esp_log_buffer_hex(DSP_TABLE_TAG, param->connect.remote_bda, 6);
		            esp_ble_conn_update_params_t conn_params = {0};
		            memcpy(conn_params.bda, param->connect.remote_bda, sizeof(esp_bd_addr_t));
		            /* For the iOS system, please refer to Apple official documents about the BLE connection parameters restrictions. */
		            conn_params.latency = 0;
		            conn_params.max_int = 0x20;    // max_int = 0x20*1.25ms = 40ms
		            conn_params.min_int = 0x10;    // min_int = 0x10*1.25ms = 20ms
		            conn_params.timeout = 400;    // timeout = 400*10ms = 4000ms
		            //start sent the update connection parameters to the peer device.
		            esp_ble_gap_update_conn_params(&conn_params);



			break;
		case ESP_GATTS_DISCONNECT_EVT:
			printf("gatts_profile_event_handler: ");
			printf("ESP_GATTS_DISCONNECT_EVT called.\n");
            esp_ble_gap_config_adv_data(&adv_data_config);
            esp_ble_gap_config_adv_data(&scan_rsp_data);
			break;
		case ESP_GATTS_CREAT_ATTR_TAB_EVT:
				printf("ESP_GATTS_CREAT_ATTR_TAB_EVT.\n");

                memcpy(dsp_control_handle_table, param->add_attr_tab.handles, sizeof(dsp_control_handle_table));
                esp_ble_gatts_start_service(dsp_control_handle_table[IDX_SVC]);
                ESP_LOGI(DSP_TABLE_TAG, "create attribute table successfully, the number handle = %d\n",param->add_attr_tab.num_handle);

			break;
        case ESP_GATTS_STOP_EVT:
        	break;
        case ESP_GATTS_OPEN_EVT:
        	break;
        case ESP_GATTS_CANCEL_OPEN_EVT:
        	break;
        case ESP_GATTS_CLOSE_EVT:
        	break;
        case ESP_GATTS_LISTEN_EVT:
        	break;
        case ESP_GATTS_CONGEST_EVT:
        	break;
        case ESP_GATTS_UNREG_EVT:
        	break;
        case ESP_GATTS_DELETE_EVT:
        	break;
        default:
            break;
		}

}
//Gets the interface from the BT stack and puts it into the table.
Gets the interface from the BT stack and puts it into the table.
Gets the interface from the BT stack and puts it into the table .
void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
{
	switch(event) {
		case ESP_GATTS_REG_EVT:
			esp_ble_gap_set_device_name(DEVICE_NAME);
			dsp_profile_tab[DSP_PROFILE_APP_IDX].gatts_if = gatts_if;
			esp_ble_gatts_create_attr_tab(dsp_db, gatts_if, NUM_TABLE_ELEMENTS, SVC_INST_ID);
            esp_ble_gap_config_adv_data(&adv_data_config);
            esp_ble_gap_config_adv_data(&scan_rsp_data);
		break;
		case ESP_GATTS_CREATE_EVT:
			break;
		case ESP_GATTS_READ_EVT:
			break;
		case ESP_GATTS_WRITE_EVT:
			if(dsp_control_handle_table[IDX_CHAR_VOL_VAL] == param->write.handle){
				float newVol = *param->write.value;
				newVol = newVol/100;
				process_coefficient_for_i2c(newVol, DSP_VOLUME_LEVEL);
				SIGMA_SAFELOAD_SINGLE(0x34, VOL_PARAM_ADDR, DSP_VOLUME_LEVEL);
			} else if (dsp_control_handle_table[IDX_CHAR_Q_VAL] == param->write.handle){
				float newQ = *param->write.value;
				newQ = newQ/25;
				float *ptr = calculate_coefficients(low_pass, gain, newQ, cutFreq);
				SIGMA_SAFELOAD_BIQUAD(0x34, BIQUAD_PARAM_BASE_ADDR, ptr);
			} else if (dsp_control_handle_table[IDX_CHAR_CUTFREQ_VAL] == param->write.handle) {
				float newCutFreq = *param->write.value *10;
				printf("New cut-off frequency value: %f\n", newCutFreq);
				printf("Q: %f  |  newCutFreq: %f\n", Q, newCutFreq);
				float *ptr = calculate_coefficients(low_pass, gain, Q, newCutFreq);
			 	SIGMA_SAFELOAD_BIQUAD(0x34, BIQUAD_PARAM_BASE_ADDR, ptr);
			} else if (dsp_control_handle_table[IDX_CHAR_GAIN_VAL] == param->write.handle){
				float newGain = *param->write.value ;
				printf("New gain value: %f\n", gain);
				printf("Q: %f  |  newCutFreq: %f\n", Q, newGain);
				float *ptr = calculate_coefficients(low_pass, newGain, Q, cutFreq);
			 	SIGMA_SAFELOAD_BIQUAD(0x34, BIQUAD_PARAM_BASE_ADDR, ptr);
			}
			break;
		case ESP_GATTS_EXEC_WRITE_EVT:
			break;
		case ESP_GATTS_CONF_EVT:
			break;
		case ESP_GATTS_MTU_EVT:
			break;
		case ESP_GATTS_START_EVT:
			break;
		case ESP_GATTS_CONNECT_EVT:
			printf("gatts_profile_event_handler: ");
					printf("ESP_GATTS_CONNECT_EVT called.\n");
		            esp_log_buffer_hex(DSP_TABLE_TAG, param->connect.remote_bda, 6);
		            esp_ble_conn_update_params_t conn_params = {0};
		            memcpy(conn_params.bda, param->connect.remote_bda, sizeof(esp_bd_addr_t));
		            conn_params.latency = 0;
		            conn_params.max_int = 0x20;    
		            conn_params.min_int = 0x10;    
		            conn_params.timeout = 400;    
		            esp_ble_gap_update_conn_params(&conn_params);
			break;
		case ESP_GATTS_DISCONNECT_EVT:
			printf("gatts_profile_event_handler: ");
			printf("ESP_GATTS_DISCONNECT_EVT called.\n");
            esp_ble_gap_config_adv_data(&adv_data_config);
            esp_ble_gap_config_adv_data(&scan_rsp_data);
			break;
		case ESP_GATTS_CREAT_ATTR_TAB_EVT:
				printf("ESP_GATTS_CREAT_ATTR_TAB_EVT.\n");
                memcpy(dsp_control_handle_table, param->add_attr_tab.handles, sizeof(dsp_control_handle_table));
                esp_ble_gatts_start_service(dsp_control_handle_table[IDX_SVC]);
                ESP_LOGI(DSP_TABLE_TAG, "create attribute table successfully, the number handle = %d\n",param->add_attr_tab.num_handle);
			break;
        case ESP_GATTS_STOP_EVT:
        	break;
        case ESP_GATTS_OPEN_EVT:
        	break;
        case ESP_GATTS_CANCEL_OPEN_EVT:
        	break;
        case ESP_GATTS_CLOSE_EVT:
        	break;
        case ESP_GATTS_LISTEN_EVT:
        	break;
        case ESP_GATTS_CONGEST_EVT:
        	break;
        case ESP_GATTS_UNREG_EVT:
        	break;
        case ESP_GATTS_DELETE_EVT:
        	break;
        default:
            break;
		}
}
void gatts_event_handler ( esp_gatts_cb_event_t event , esp_gatt_if_t gatts_if , esp_ble_gatts_cb_param_t * param ) { switch ( event ) { case ESP_GATTS_REG_EVT : esp_ble_gap_set_device_name ( DEVICE_NAME ) ; dsp_profile_tab [ DSP_PROFILE_APP_IDX ] . gatts_if = gatts_if ; esp_ble_gatts_create_attr_tab ( dsp_db , gatts_if , NUM_TABLE_ELEMENTS , SVC_INST_ID ) ; esp_ble_gap_config_adv_data ( & adv_data_config ) ; esp_ble_gap_config_adv_data ( & scan_rsp_data ) ; break ; case ESP_GATTS_CREATE_EVT : break ; case ESP_GATTS_READ_EVT : break ; case ESP_GATTS_WRITE_EVT : if ( dsp_control_handle_table [ IDX_CHAR_VOL_VAL ] == param -> write . handle ) { float newVol = * param -> write . value ; newVol = newVol / 100 ; process_coefficient_for_i2c ( newVol , DSP_VOLUME_LEVEL ) ; SIGMA_SAFELOAD_SINGLE ( 0x34 , VOL_PARAM_ADDR , DSP_VOLUME_LEVEL ) ; } else if ( dsp_control_handle_table [ IDX_CHAR_Q_VAL ] == param -> write . handle ) { float newQ = * param -> write . value ; newQ = newQ / 25 ; float * ptr = calculate_coefficients ( low_pass , gain , newQ , cutFreq ) ; SIGMA_SAFELOAD_BIQUAD ( 0x34 , BIQUAD_PARAM_BASE_ADDR , ptr ) ; } else if ( dsp_control_handle_table [ IDX_CHAR_CUTFREQ_VAL ] == param -> write . handle ) { float newCutFreq = * param -> write . value * 10 ; printf ( " \n " , newCutFreq ) ; printf ( " \n " , Q , newCutFreq ) ; float * ptr = calculate_coefficients ( low_pass , gain , Q , newCutFreq ) ; SIGMA_SAFELOAD_BIQUAD ( 0x34 , BIQUAD_PARAM_BASE_ADDR , ptr ) ; } else if ( dsp_control_handle_table [ IDX_CHAR_GAIN_VAL ] == param -> write . handle ) { float newGain = * param -> write . value ; printf ( " \n " , gain ) ; printf ( " \n " , Q , newGain ) ; float * ptr = calculate_coefficients ( low_pass , newGain , Q , cutFreq ) ; SIGMA_SAFELOAD_BIQUAD ( 0x34 , BIQUAD_PARAM_BASE_ADDR , ptr ) ; } break ; case ESP_GATTS_EXEC_WRITE_EVT : break ; case ESP_GATTS_CONF_EVT : break ; case ESP_GATTS_MTU_EVT : break ; case ESP_GATTS_START_EVT : break ; case ESP_GATTS_CONNECT_EVT : printf ( " " ) ; printf ( " \n " ) ; esp_log_buffer_hex ( DSP_TABLE_TAG , param -> connect . remote_bda , 6 ) ; esp_ble_conn_update_params_t conn_params = { 0 } ; memcpy ( conn_params . bda , param -> connect . remote_bda , sizeof ( esp_bd_addr_t ) ) ; conn_params . latency = 0 ; conn_params . max_int = 0x20 ; conn_params . min_int = 0x10 ; conn_params . timeout = 400 ; esp_ble_gap_update_conn_params ( & conn_params ) ; break ; case ESP_GATTS_DISCONNECT_EVT : printf ( " " ) ; printf ( " \n " ) ; esp_ble_gap_config_adv_data ( & adv_data_config ) ; esp_ble_gap_config_adv_data ( & scan_rsp_data ) ; break ; case ESP_GATTS_CREAT_ATTR_TAB_EVT : printf ( " \n " ) ; memcpy ( dsp_control_handle_table , param -> add_attr_tab . handles , sizeof ( dsp_control_handle_table ) ) ; esp_ble_gatts_start_service ( dsp_control_handle_table [ IDX_SVC ] ) ; ESP_LOGI ( DSP_TABLE_TAG , " \n " , param -> add_attr_tab . num_handle ) ; break ; case ESP_GATTS_STOP_EVT : break ; case ESP_GATTS_OPEN_EVT : break ; case ESP_GATTS_CANCEL_OPEN_EVT : break ; case ESP_GATTS_CLOSE_EVT : break ; case ESP_GATTS_LISTEN_EVT : break ; case ESP_GATTS_CONGEST_EVT : break ; case ESP_GATTS_UNREG_EVT : break ; case ESP_GATTS_DELETE_EVT : break ; default : break ; } }
Gets the interface from the BT stack and puts it into the table.
Gets the interface from the BT stack and puts it into the table .
/* For the iOS system, please refer to Apple official documents about the BLE connection parameters restrictions. */ // max_int = 0x20*1.25ms = 40ms // min_int = 0x10*1.25ms = 20ms // timeout = 400*10ms = 4000ms //start sent the update connection parameters to the peer device.