/******************************************************************************* * @file measurements.c * @author CandyPops Co. * @version V1.0.0 * @date 2022-09-05 * @brief ******************************************************************************/ #include "sdk_common.h" #include #include #include #include #include "nrf.h" #include "nrf_drv_gpiote.h" #include "nrf_drv_spi.h" #include "nrf_drv_saadc.h" #include "nrf_drv_ppi.h" #include "nrf_drv_timer.h" #include "boards.h" #include "bsp.h" #include "app_error.h" #include "nrf_delay.h" #include "app_util_platform.h" #include "nrf_pwr_mgmt.h" #include "nrf_log.h" #include "ble_nus.h" #include "LED_Parse.h" #include "app_timer.h" #include "measurements.h" #include "main.h" //#include "fstorage.h" #include "ad5272_i2c.h" #include "mcp4725_i2c.h" #include #include "debug_print.h" #include "i2c_manager.h" //#define trig_18 NRF_GPIO_PIN_MAP(0,18) //#define tris_18_CONFIG() nrf_gpio_cfg_output(trig_18) //#define trig_on() nrf_gpio_pin_set(trig_18) //#define trig_off() nrf_gpio_pin_clear(trig_18) #define LED_NUM 24 // uint8_t activated_led = 99; uint8_t activated_pd = 99; APP_TIMER_DEF(m_mea_send_loop_timer_id); static uint8_t cnt =0; #define MEA_SEND_LOOP_INTERVAL 100 char mea_tx_buffer[BLE_NUS_MAX_DATA_LEN]; extern volatile bool processing; /* Default Value before initialized. Set value for Default!!! */ /* 초기값 설정 */ /* 0번은 사용하지 않음 = NULL, 1 ~ 24까지 사용 */ /*AD5272 DP에 쓸수 있는 값 범위는 0 ~ 1023 */ //uint16_t led_power_dp[LED_NUM] = { // // 0,25,25,18,19,24,24,25,25,18,19,25,23,25,25,18,19,24,24,25,25,19,20,25 //}; //uint16_t led_power_dp[48] = // {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47}; // /*LED0 = NULL 사용하지 않음, LED1, LED2, LED3, LED4, LED5, LED6, LED7, LED8, LED9, LED10, LED11, LED12, LED13, LED14, LED15, LED16, LED17, LED18, LED19, LED20, LED21, LED22, LED23, LED24 */ /*MCP4725 를 0.1V(125) ~ 1.1V(1366) 값을 사용 */ //uint16_t led_pd_dac_v[LED_NUM] = // {1000, 1000, 1000, 1000, 1000, 1000, 1000,1000, 1000, 1000, 1000, 1000, 1000, 1000,1000, 1000, 1000, 1000, 1000, 1000, 1000,1000, 1000, 1000, /* PD0 */ // 1000, 1000, 1000, 1000, 1000, 1000, 1000,1000, 1000, 1000, 1000, 1000, 1000, 1000,1000, 1000, 1000, 1000, 1000, 1000, 1000,1000, 1000, 1000}; /* PD1 */ // uint16_t led_pd_dac_v[LED_NUM] = {1000, 1000, 1000, 1000, 1000, 1000, 1000,1000, 1000, 1000, 1000, 1000, 1000, 1000,1000, 1000, 1000, 1000, 1000, 1000, 1000,1000, 1000, 1000}; /* PD0 */ // 48 에서 24 변경 cj chun uint16_t led_off_dac_v =1360; uint8_t led_off_pd = 0; /*ello Annapalu As Wojtek already stated you cannot use the nrf_gpio_pin_read to read a pin set as an output. If you look at figure 21, page 112 in the nRF52832 product specification you can see the PIN(0).IN register, it is this register that is read by the gpio_pin_read function. When a pin is set as an output the PIN(0).CNF.DIR switch will close on the output side and open on the input side, meaning it is physically impossible to read the actual output value of the pin with the input register. Wojtek is also correct that the NRF_GPIO->OUT only shows whether you have set the register, and not the actual pin state. To achieve what you want you could connect a second GPIO, configured as an input, to the same circuit. This would tell you whether the voltage is high or low. If you need to see a more accurate reading of the voltage level, to detect deviation, you could use the ADC or Comparator. EDIT: 23.03.17 14:40 I have looked further into this and it seems I was a bit hasty in my reply. The product specification shows the control signal of the two above mentioned switches are different. PIN(0).CNF.DIR for the output and PIN(0).CNF.INPUT for the input buffer.So it seems it is possible to read the output value (high or low) of an output pin using the nrf_gpio_pin_read function, if you both set the direction of the pin to output, and connect the input buffer. This can be done with the nrf_gpio_cfg() function. Note that the nrf_gpio_cfg_output() function disconnects the input buffer. I have tested it on the PCA10040 both with a led toggling based on it's own pin_read value, and with 4 leds switching based on the input value of one of the other led pins, all are configured as outputs. */ void led_pd_gain_array_printout(void) { cnt=0; mea_send_timer_start(); } void mea_send_loop(void * p_context) /* For x ms */ { UNUSED_PARAMETER(p_context); DBG_PRINTF("\r\n1CNT =%d\r\n",cnt); mea_send_timer_stop(); if (cnt < 6) { uint8_t i = (int)(cnt); if (cnt<3){ // sprintf(mea_tx_buffer, "Tag-Currrnt %d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d\r\n", i, led_pd_dac_v[i][0], led_pd_dac_v[i][1], led_pd_dac_v[i][2], led_pd_dac_v[i][3], led_pd_dac_v[i][4], led_pd_dac_v[i][5], led_pd_dac_v[i][6], led_pd_dac_v[i][7],led_pd_dac_v[i][8], led_pd_dac_v[i][9], led_pd_dac_v[i][10], // led_pd_dac_v[i][11], led_pd_dac_v[i][12], led_pd_dac_v[i][13], led_pd_dac_v[i][14], led_pd_dac_v[i][15], led_pd_dac_v[i][16], led_pd_dac_v[i][17],led_pd_dac_v[i][18], led_pd_dac_v[i][19], led_pd_dac_v[i][20], led_pd_dac_v[i][21],led_pd_dac_v[i][22], led_pd_dac_v[i][23]); // data_tx_handler(mea_tx_buffer); } sprintf(mea_tx_buffer, "Tag-Currrnt %d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d\r\n", i, led_pd_dac_v[0], led_pd_dac_v[1], led_pd_dac_v[2], led_pd_dac_v[3], led_pd_dac_v[4], led_pd_dac_v[5], led_pd_dac_v[6], led_pd_dac_v[7],led_pd_dac_v[8], led_pd_dac_v[9], led_pd_dac_v[10], led_pd_dac_v[11], led_pd_dac_v[12], led_pd_dac_v[13], led_pd_dac_v[14], led_pd_dac_v[15], led_pd_dac_v[16], led_pd_dac_v[17],led_pd_dac_v[18], led_pd_dac_v[19], led_pd_dac_v[20], led_pd_dac_v[21],led_pd_dac_v[22], led_pd_dac_v[23]); data_tx_handler(mea_tx_buffer); } else{ } DBG_PRINTF("\r\n2CNT =%d\r\n",cnt); mea_send_timer_start(); // switch(cnt){ // case 0: // break; // case 1: // sprintf(mea_tx_buffer, "Tag-Currrnt %d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d\r\n", i, 0,led_pd_dac_v_led_1[1], led_pd_dac_v_led_2[1], led_pd_dac_v_led_3[1], led_pd_dac_v_led_4[1], led_pd_dac_v_led_5[1], led_pd_dac_v_led_6[1], led_pd_dac_v_led_7[1], led_pd_dac_v_led_8[1], // led_pd_dac_v_led_9[1], led_pd_dac_v_led_10[1], led_pd_dac_v_led_11[1], led_pd_dac_v_led_12[1], led_pd_dac_v_led_13[1], led_pd_dac_v_led_14[1], led_pd_dac_v_led_15[1], led_pd_dac_v_led_16[1], led_pd_dac_v_led_17[1],led_pd_dac_v_led_18[1], // led_pd_dac_v_led_19[1], led_pd_dac_v_led_20[1],led_pd_dac_v_led_21[1], led_pd_dac_v_led_22[1],led_pd_dac_v_led_23[1], led_pd_dac_v_led_24[1]); // break; // case 2: // sprintf(mea_tx_buffer, "Tag-Currrnt %d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d\r\n", i, 0, led_pd_dac_v_led_1[1], led_pd_dac_v_led_2[1], led_pd_dac_v_led_3[1], led_pd_dac_v_led_4[1], led_pd_dac_v_led_5[1], led_pd_dac_v_led_6[1], led_pd_dac_v_led_7[1], led_pd_dac_v_led_8[1], // led_pd_dac_v_led_9[1], led_pd_dac_v_led_10[1], led_pd_dac_v_led_11[1], led_pd_dac_v_led_12[1], led_pd_dac_v_led_13[1], led_pd_dac_v_led_14[1], led_pd_dac_v_led_15[1], led_pd_dac_v_led_16[1], led_pd_dac_v_led_17[1],led_pd_dac_v_led_18[1], // led_pd_dac_v_led_19[1], led_pd_dac_v_led_20[1],led_pd_dac_v_led_21[1], led_pd_dac_v_led_22[1],led_pd_dac_v_led_23[1], led_pd_dac_v_led_24[1]); // break; // case 3: // sprintf(mea_tx_buffer, "Tag-Currrnt %d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d\r\n", i,0, led_pd_dac_v_led_1[1], led_pd_dac_v_led_2[1], led_pd_dac_v_led_3[1], led_pd_dac_v_led_4[1], led_pd_dac_v_led_5[1], led_pd_dac_v_led_6[1], led_pd_dac_v_led_7[1], led_pd_dac_v_led_8[1], // led_pd_dac_v_led_9[1], led_pd_dac_v_led_10[1], led_pd_dac_v_led_11[1], led_pd_dac_v_led_12[1], led_pd_dac_v_led_13[1], led_pd_dac_v_led_14[1], led_pd_dac_v_led_15[1], led_pd_dac_v_led_16[1], led_pd_dac_v_led_17[1],led_pd_dac_v_led_18[1], // led_pd_dac_v_led_19[1], led_pd_dac_v_led_20[1],led_pd_dac_v_led_21[1], led_pd_dac_v_led_22[1],led_pd_dac_v_led_23[1], led_pd_dac_v_led_24[1]); // break; // default: // break; //// } // sprintf(mea_tx_buffer,"CNT_%d\r\n",cnt); // data_tx_handler(mea_tx_buffer); // // mea_send_timer_start(); } else { //battery_timer_start(); // sprintf(mea_tx_buffer,"END \r\n"); // data_tx_handler(mea_tx_buffer); // printf("\r\nLED-DP Gain Array =\r\n"); // for(uint16_t i = 0; i < LED_NUM; i++){ // printf("%d,\t", m_config.led_power_dp[i]); // } // printf("\r\n"); DBG_PRINTF("\r\nLED-PD Gain Array =\r\n"); // for(uint16_t i = 0; i < PD_NUM; i++){ for(uint16_t j = 0; j < LED_NUM; j++){ DBG_PRINTF("%d,\t", led_pd_dac_v[j]); // } // ///break; // DBG_PRINTF("\r\n"); } DBG_PRINTF("\r\n"); processing = false ; } cnt++; } ret_code_t led_on(uint8_t led_index) { uint32_t err_code = NRF_SUCCESS; #if FEATURE_PRINTF DBG_PRINTF("\tled_on, %d =====================\r\n", led_index); #endif // if((led_index >= 0)&&(led_index <= 49)){ if(led_index <= 100){ activated_led = led_index; //LED off 적용을 위해 /* LED켤때 파워 셋팅한후 켜는지 결정요 */ // if(NRF_SUCCESS != led_power_set(led_index)) { // DBG_PRINTF("ERR!!! LED Power set\r\n"); // return NRF_ERROR_INTERNAL; // } //nrf_gpio_pin_set(trig_18); trig_SW(true); if(NRF_SUCCESS != led_select(led_index)){ DBG_PRINTF("ERR!!! LED Select\r\n"); return NRF_ERROR_INTERNAL; } // VCSEL_SW(true); }else{ DBG_PRINTF("ERR!!! led_index Failed! %d\r\n", led_index); return NRF_ERROR_INTERNAL; } return err_code; } ret_code_t led_off(uint8_t led_index) { uint32_t err_code = NRF_SUCCESS; trig_SW(false); #if FEATURE_PRINTF DBG_PRINTF("led_off\r\n"); #endif if(led_index == 99){ LED_ALLOFF(); activated_led = 99; } else if(led_index == 98){ LED99(); DBG_PRINTF("clear \r\n"); activated_led = 98; } else{ DBG_PRINTF("ERR!!! led_index Failed! %d\r\n", led_index); return NRF_ERROR_INTERNAL; } uint32_t port_state0 = nrf_gpio_port_out_read(NRF_P0); uint32_t port_state1 = nrf_gpio_port_out_read(NRF_P1); // DBG_PRINTF("test : %d, %d \r\n",port_state0,port_state1); // DBG_PRINTF("LIGHT ON1 : %d \r\n",port_state0>>22&1); // DBG_PRINTF("LIGHT ON2 : %d \r\n",port_state0>>23&1); // DBG_PRINTF("LED_SEL_SW1 : %d \r\n",port_state1>>4&1); // DBG_PRINTF("LED_SEL_SW2 : %d \r\n",port_state1>>5&1); // DBG_PRINTF("LED_SEL_SW3 : %d \r\n",port_state1>>6&1); // DBG_PRINTF("LED_INDIV_SEL_SW1 : %d \r\n",port_state1>>1&1); // DBG_PRINTF("LED_INDIV_SEL_SW2 : %d \r\n",port_state1>>2&1); // DBG_PRINTF("LED_INDIV_SEL_SW3 : %d \r\n",port_state1>>3&1); return err_code; } ret_code_t led_pd_mod_set(uint16_t mod_gain) { uint32_t err_code = NRF_SUCCESS; // if(((led_index >= 0)&&(led_index <= 49))||((pd_index >= 0)&&(pd_index <= 2))){ if(mod_gain <= 2000){ sw_i2c_init_once(); mcp4725_writeFastMode( mod_gain); if(NRF_SUCCESS != pd_on(2)){ //0~23 ==pd0 24~47 == pd1 DBG_PRINTF("ERR!!! MOD_on\r\n"); return NRF_ERROR_INTERNAL; } }else{ DBG_PRINTF("ERR!!! lockin Test Failed! \r\n"); return NRF_ERROR_INTERNAL; } return err_code; } ret_code_t led_pd_matching_value_set(uint8_t led_index) { uint32_t err_code = NRF_SUCCESS; // if(((led_index >= 0)&&(led_index <= 49))||((pd_index >= 0)&&(pd_index <= 2))){ if(led_index <= 100){ if(NRF_SUCCESS != pd_gain_set(led_index)){ DBG_PRINTF("ERR!!! pd_gain_set\r\n"); return NRF_ERROR_INTERNAL; } uint8_t pd_index; if(led_index<24) {pd_index =0; } else if ((led_index<48) && (led_index>23) ) {pd_index =1; } else if (led_index==99) { pd_index = led_off_pd; } if(NRF_SUCCESS != pd_on(pd_index)){ //0~23 ==pd0 24~47 == pd1 DBG_PRINTF("ERR!!! pd_on\r\n"); return NRF_ERROR_INTERNAL; } }else{ DBG_PRINTF("ERR!!! led_indexFailed! %d\r\n", led_index); return NRF_ERROR_INTERNAL; } return err_code; } ret_code_t pd_on(uint8_t pd_index) { uint32_t err_code = NRF_SUCCESS; #if FEATURE_FOR_SCOPE nrf_gpio_pin_set(PD_CLK_26); nrf_gpio_pin_clear(PD_CLK_26); #endif #if FEATURE_PRINTF DBG_PRINTF("pd_on, %d ===== \r\n", pd_index); #endif // if((pd_index >= 0)&&(pd_index <= 2)){ if(pd_index <= 3){ activated_pd = pd_index; //DBG_PRINTF("pd_on %d\r\n", pd_index); if(NRF_SUCCESS != pd_select(pd_index)){ DBG_PRINTF("ERR!!! pd_on Failed! %d\r\n", pd_index); return NRF_ERROR_INTERNAL; } }else{ DBG_PRINTF("ERR!!! pd_index Failed! %d\r\n", pd_index); return NRF_ERROR_INTERNAL; } return err_code; } ret_code_t pd_off(uint8_t pd_index) { uint32_t err_code = NRF_SUCCESS; #if FEATURE_PRINTF DBG_PRINTF("pd_off\r\n"); #endif if(pd_index == 99){ PD_ALLOFF(); activated_pd = 99; }else{ DBG_PRINTF("ERR!!! PD Off Failed! %d\r\n", pd_index); return NRF_ERROR_INTERNAL; } return err_code; } void led_power_read_48(uint16_t *data) { for(uint8_t i = 0 ; i<24 ;i++){ //48 >24 data[i] = LED_READ_ROM(i); nrf_delay_ms(1); } // nrf_delay_ms(20); } int16_t led_power_read(uint8_t led_index) { int16_t led_power; // if((led_index >= 0)&&(led_index <= 49)){ if(led_index <= 47){ //led_power = led_power_dp[led_index]; led_power = LED_READ_ROM(led_index); }else{ DBG_PRINTF("ERR!!! led_index Failed! %d\r\n", led_index); return NRF_ERROR_INTERNAL; } return led_power; } ret_code_t led_power_save_mem(uint8_t led_index, int16_t led_power) /* 커맨드에 의해서 LED파워 값을 저장할때 */ { uint32_t err_code = NRF_SUCCESS; // if(((led_index >= 0)&&(led_index <= 49))||((led_power >= 0)&&(led_power <= 255))){ if((led_index <= 47)||(led_power <= 255)){ // led_power_dp[led_index] = led_power; if(NRF_SUCCESS != LED_WRITE_ROM(led_index,led_power)){ DBG_PRINTF("ERR!!! DS3930 1\r\n"); err_code = NRF_ERROR_INTERNAL; } }else{ DBG_PRINTF("ERR!!! led_index || pd_index Failed! %d, %d\r\n", led_index, led_power); return NRF_ERROR_INTERNAL; } return err_code; } ret_code_t led_power_save_mem_6(uint8_t led_index, int16_t led_power) /* 커맨드에 의해서 LED파워 값을 저장할때 */ { uint32_t err_code = NRF_SUCCESS; // if(((led_index >= 0)&&(led_index <= 49))||((led_power >= 0)&&(led_power <= 255))){ // if((led_index <= 47)||(led_power <= 255)){ // led_power_dp[led_index] = led_power; // for(uint8_t i = 0 ; i<48 ;i++){ // if(NRF_SUCCESS != LED_WRITE_ROM(led_index,led_power)){ // DBG_PRINTF("ERR!!! DS3930 1\r\n"); // err_code = NRF_ERROR_INTERNAL; for(uint8_t i = 0 ; i<48 ;i++){ // led_power_dp[i] = led_power; Fstorage garbage if(NRF_SUCCESS != LED_WRITE_ROM(i,led_power)){ DBG_PRINTF("ERR!!! DS3930 1\r\n"); err_code = NRF_ERROR_INTERNAL; } // nrf_delay_ms(20); else{ // DBG_PRINTF("ERR!!! led_index Failed! %d\r\n", led_index); // return NRF_ERROR_INTERNAL; } nrf_delay_ms(10); } return err_code; } ret_code_t led_power_save_mem_48(uint8_t *led_power) /* 커맨드에 의해서 LED파워 값을 저장할때 */ { uint32_t err_code = NRF_SUCCESS; // if(((led_index >= 0)&&(led_index <= 49))||((led_power >= 0)&&(led_power <= 255))){ // if((led_index <= 47)||(led_power <= 255)){ // led_power_dp[led_index] = led_power; // for(uint8_t i = 0 ; i<48 ;i++){ // if(NRF_SUCCESS != LED_WRITE_ROM(led_index,led_power)){ // DBG_PRINTF("ERR!!! DS3930 1\r\n"); // err_code = NRF_ERROR_INTERNAL; for(uint8_t i = 0 ; i<48 ;i++){ //led_power_dp[i] = led_power; if(NRF_SUCCESS != LED_WRITE_ROM(i,(int16_t)(led_power[i]))){ DBG_PRINTF("ERR!!! DS3930 1\r\n"); err_code = NRF_ERROR_INTERNAL; } // nrf_delay_ms(20); else{ // DBG_PRINTF("ERR!!! led_index Failed! %d\r\n", led_index); // return NRF_ERROR_INTERNAL; } nrf_delay_ms(10); } return err_code; } //void led_power_span(uint8_t led_index) //{ // uint32_t err_code = NRF_SUCCESS; // // for(uint8_t i= 0 ;i<255 ;i++){ // if(NRF_SUCCESS != LED_WRITE_ROM(led_index,i)){ // DBG_PRINTF("ERR!!! DS3930 1\r\n"); // err_code = NRF_ERROR_INTERNAL; // } // nrf_delay_ms(20); // } // DBG_PRINTF("DS3930 1\r\n"); // } ret_code_t led_power_set(uint8_t led_index) /* LED켤때 사용, 메모리 값을 디지털포텐셔미터에 입력 */ { uint32_t err_code = NRF_SUCCESS; // int16_t led_power; //no need // if((led_index >= 1)&&(led_index <= 24)){ // led_power = led_power_dp[led_index]; // if(NRF_SUCCESS != ad5272_write_rdac(led_power)) { /* LED를 켜기전에 메모리에 저장된 파워값을 DAC에 설정 */ // DBG_PRINTF("ERR!!! ad5272_write_rdac 2\r\n"); // err_code = NRF_ERROR_INTERNAL; // } // }else{ // DBG_PRINTF("ERR!!! led_index Failed! %d\r\n", led_index); // return NRF_ERROR_INTERNAL; // } return err_code; } ret_code_t pd_gain_set(uint8_t activated_led) /* LED와 PD 매칭 값으로 On */ { uint32_t err_code = NRF_SUCCESS; #if FEATURE_PRINTF DBG_PRINTF("<>\r\n",activated_led ,pd_index); #endif // if(((activated_led >= 0)&&(activated_led <= 49))||((pd_index >= 0)&&(pd_index <= 2))){ if((activated_led <= 47)){ sw_i2c_init_once(); mcp4725_writeFastMode( led_pd_dac_v[activated_led]); /* LED는 먼저 ON되어 있어 하며 그 LED번호와 PD배칭 값으로 DAC에 설정 */ //DBG_PRINTF("dac_v %d\r\n", led_pd_dac_v[pd_index][activated_led]); } else if(activated_led == 99){ mcp4725_writeFastMode( led_off_dac_v); /* LED_OFF 배칭 값으로 DAC에 설정 */ } else{ DBG_PRINTF("ERR!!! led_index Failed! %d\r\n", activated_led); return NRF_ERROR_INTERNAL; } return err_code; } ret_code_t imm_gain_set(uint16_t imm_dac) /* LED와 PD 매칭 값으로 On */ { uint32_t err_code = NRF_SUCCESS; if((imm_dac <= 2000)){ sw_i2c_init_once();//ad cj mcp4725_writeFastMode( imm_dac); /* LED는 먼저 ON되어 있어 하며 그 LED번호와 PD배칭 값으로 DAC에 설정 */ DBG_PRINTF("dac_v %d\r\n", imm_dac); }else{ DBG_PRINTF("ERR!!! range Failed! %d\r\n", activated_led); return NRF_ERROR_INTERNAL; } return err_code; } ret_code_t led_select(uint8_t led_index) { uint32_t err_code = NRF_SUCCESS; //LED_ALLOFF(); switch(led_index) { case 0: LED0(); break; case 1: LED1(); break; case 2: LED2(); break; case 3: LED3(); break; case 4: LED4(); break; case 5: LED5(); break; case 6: LED6(); break; case 7: LED7(); break; case 8: LED8(); break; case 9: LED9(); break; case 10: LED10(); break; case 11: LED11(); break; case 12: LED12(); break; case 13: LED13(); break; case 14: LED14(); break; case 15: LED15(); break; case 16: LED16(); break; case 17: LED17(); break; case 18: LED18(); break; case 19: LED19(); break; case 20: LED20(); break; case 21: LED21(); break; case 22: LED22(); break; case 23: LED23(); break; case 24: LED24(); break; case 25: LED25(); break; case 26: LED26(); break; case 27: LED27(); break; case 28: LED28(); break; case 29: LED29(); break; case 30: LED30(); break; case 31: LED31(); break; case 32: LED32(); break; case 33: LED33(); break; case 34: LED34(); break; case 35: LED35(); break; case 36: LED36(); break; case 37: LED37(); break; case 38: LED38(); break; case 39: LED39(); break; case 40: LED40(); break; case 41: LED41(); break; case 42: LED42(); break; case 43: LED43(); break; case 44: LED44(); break; case 45: LED45(); break; case 46: LED46(); break; case 47: LED47(); break; case 99: LED99(); break; default: err_code = NRF_ERROR_NOT_FOUND; break; } nrf_delay_ms(1); // DBG_PRINTF("LIGHT ON1 : %d \r\n",nrf_gpio_pin_read(LIGHT_ON1)); // DBG_PRINTF("LIGHT ON2 : %d \r\n",nrf_gpio_pin_read(LIGHT_ON2)); // DBG_PRINTF("LED_SEL_SW1 : %d \r\n",nrf_gpio_pin_read(LED_SEL_SW1)); // DBG_PRINTF("LED_SEL_SW2 : %d \r\n",nrf_gpio_pin_read(LED_SEL_SW2)); // DBG_PRINTF("LED_SEL_SW3 : %d \r\n",nrf_gpio_pin_read(LED_SEL_SW3)); // DBG_PRINTF("LED_INDIV_SEL_SW1 : %d \r\n",nrf_gpio_pin_read(LED_INDIV_SEL_SW1)); // DBG_PRINTF("LED_INDIV_SEL_SW2 : %d \r\n",nrf_gpio_pin_read(LED_INDIV_SEL_SW2)); // DBG_PRINTF("LED_INDIV_SEL_SW3 : %d \r\n",nrf_gpio_pin_read(LED_INDIV_SEL_SW3)); uint32_t port_state0 = nrf_gpio_port_out_read(NRF_P0); uint32_t port_state1 = nrf_gpio_port_out_read(NRF_P1); // DBG_PRINTF("test : %d, %d \r\n",port_state0,port_state1); // DBG_PRINTF("LIGHT ON1 : %d \r\n",port_state0>>22&1); // DBG_PRINTF("LIGHT ON2 : %d \r\n",port_state0>>23&1); // DBG_PRINTF("LED_SEL_SW1 : %d \r\n",port_state1>>4&1); // DBG_PRINTF("LED_SEL_SW2 : %d \r\n",port_state1>>5&1); // DBG_PRINTF("LED_SEL_SW3 : %d \r\n",port_state1>>6&1); // DBG_PRINTF("LED_INDIV_SEL_SW1 : %d \r\n",port_state1>>1&1); // DBG_PRINTF("LED_INDIV_SEL_SW2 : %d \r\n",port_state1>>2&1); // DBG_PRINTF("LED_INDIV_SEL_SW3 : %d \r\n",port_state1>>3&1); return err_code; } ret_code_t pd_select(uint8_t pd_index) { uint32_t err_code = NRF_SUCCESS; PD_ALLOFF(); switch(pd_index) { case 0: PD0(); break; case 1: PD1(); break; case 2: MOD(); break; case 3: MOD2(); break; default: err_code = NRF_ERROR_NOT_FOUND; break; } return err_code; } void mea_send_timer_start(void) { APP_ERROR_CHECK(app_timer_start(m_mea_send_loop_timer_id, APP_TIMER_TICKS(MEA_SEND_LOOP_INTERVAL), NULL)); } void mea_send_timer_stop(void) { APP_ERROR_CHECK(app_timer_stop(m_mea_send_loop_timer_id)); } void mea_send_timer_init(void) { APP_ERROR_CHECK(app_timer_create(&m_mea_send_loop_timer_id, APP_TIMER_MODE_SINGLE_SHOT, mea_send_loop)); }