Skip to content

Commit 83ce92f

Browse files
GoldenBugfacebook-github-bot
authored andcommitted
Refactor plat_sensor to Extract Common Functions.
Summary: plat_get_config_size(...) and load_sensor_config(...) were common between all sensor configs for most of the platforms. This commit extracts those functions and places them into the common sensor files. Reviewed By: garnermic Differential Revision: D38228111 fbshipit-source-id: e5e1f861411408bbc8d13fcbe097b3df388272ac
1 parent 10e23f1 commit 83ce92f

10 files changed

Lines changed: 24 additions & 73 deletions

File tree

‎common/service/sensor/sensor.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424

2525
#define SENSOR_READ_RETRY_MAX 3
2626

27+
extern sensor_cfg plat_sensor_config[];
28+
extern const int SENSOR_CONFIG_SIZE;
29+
2730
struct k_thread sensor_poll;
2831
K_KERNEL_STACK_MEMBER(sensor_poll_stack, SENSOR_POLL_STACK_SIZE);
2932

@@ -545,3 +548,14 @@ bool check_is_sensor_ready()
545548
{
546549
return is_sensor_ready_flag;
547550
}
551+
552+
uint8_t plat_get_config_size()
553+
{
554+
return SENSOR_CONFIG_SIZE;
555+
}
556+
557+
__weak void load_sensor_config(void)
558+
{
559+
memcpy(sensor_config, plat_sensor_config, SENSOR_CONFIG_SIZE);
560+
sensor_config_count = SENSOR_CONFIG_SIZE;
561+
}

‎common/service/sensor/sensor.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,5 +361,7 @@ bool check_sensor_num_exist(uint8_t sensor_num);
361361
void add_sensor_config(sensor_cfg config);
362362
bool check_is_sensor_ready();
363363
bool pal_is_time_to_poll(uint8_t sensor_num, int poll_time);
364+
uint8_t plat_get_config_size();
365+
void load_sensor_config(void);
364366

365367
#endif

‎meta-facebook/gt-cc/src/platform/plat_sensor_table.c‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -652,13 +652,4 @@ sensor_cfg plat_sensor_config[] = {
652652
post_i2c_bus_read, NULL, &ssd_sensor_init_args[15] },
653653
};
654654

655-
uint8_t plat_get_config_size()
656-
{
657-
return ARRAY_SIZE(plat_sensor_config);
658-
}
659-
660-
void load_sensor_config(void)
661-
{
662-
memcpy(sensor_config, plat_sensor_config, sizeof(plat_sensor_config));
663-
sensor_config_count = ARRAY_SIZE(plat_sensor_config);
664-
}
655+
const int SENSOR_CONFIG_SIZE = ARRAY_SIZE(plat_sensor_config);

‎meta-facebook/wc-mb/src/platform/plat_sensor_table.c‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,4 @@ sensor_cfg plat_sensor_config[] = {
136136
SENSOR_INIT_STATUS, NULL, NULL, NULL, NULL, &mp5990_init_args[0] },
137137
};
138138

139-
uint8_t plat_get_config_size()
140-
{
141-
return ARRAY_SIZE(plat_sensor_config);
142-
}
143-
144-
void load_sensor_config(void)
145-
{
146-
memcpy(sensor_config, plat_sensor_config, sizeof(plat_sensor_config));
147-
sensor_config_count = ARRAY_SIZE(plat_sensor_config);
148-
}
139+
const int SENSOR_CONFIG_SIZE = ARRAY_SIZE(plat_sensor_config);

‎meta-facebook/yv3-dl/src/platform/plat_sensor_table.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,7 @@ sensor_cfg isl69254_sensor_config_table[] = {
301301
NULL },
302302
};
303303

304-
uint8_t plat_get_config_size()
305-
{
306-
return ARRAY_SIZE(plat_sensor_config);
307-
}
304+
const int SENSOR_CONFIG_SIZE = ARRAY_SIZE(plat_sensor_config);
308305

309306
void load_sensor_config(void)
310307
{

‎meta-facebook/yv3-vf/src/platform/plat_sensor_table.c‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,4 @@ sensor_cfg plat_sensor_config[] = {
1616
pre_sensor_read_fn, pre_sensor_read_args, post_sensor_read_fn, post_sensor_read_fn */
1717
};
1818

19-
uint8_t plat_get_config_size()
20-
{
21-
return ARRAY_SIZE(plat_sensor_config);
22-
}
23-
24-
void load_sensor_config(void)
25-
{
26-
memcpy(sensor_config, plat_sensor_config, sizeof(plat_sensor_config));
27-
sensor_config_count = ARRAY_SIZE(plat_sensor_config);
28-
}
19+
const int SENSOR_CONFIG_SIZE = ARRAY_SIZE(plat_sensor_config);

‎meta-facebook/yv35-bb/src/platform/plat_sensor_table.c‎

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,4 @@ sensor_cfg plat_sensor_config[] = {
9090
SENSOR_INIT_STATUS, NULL, NULL, NULL, NULL, &adm1278_init_args[0] },
9191
};
9292

93-
uint8_t plat_get_config_size()
94-
{
95-
return ARRAY_SIZE(plat_sensor_config);
96-
}
97-
98-
void load_sensor_config(void)
99-
{
100-
memcpy(sensor_config, plat_sensor_config, sizeof(plat_sensor_config));
101-
sensor_config_count = ARRAY_SIZE(plat_sensor_config);
102-
}
103-
104-
uint8_t get_hsc_pwr_reading(int *reading)
105-
{
106-
return get_sensor_reading(SENSOR_NUM_PWR_HSCIN, reading, GET_FROM_CACHE);
107-
}
93+
const int SENSOR_CONFIG_SIZE = ARRAY_SIZE(plat_sensor_config);

‎meta-facebook/yv35-cl/src/platform/plat_sensor_table.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,7 @@ sensor_cfg DPV2_sensor_config_table[] = {
289289
SENSOR_INIT_STATUS, NULL, NULL, NULL, NULL, &max16550a_init_args[0] },
290290
};
291291

292-
uint8_t plat_get_config_size()
293-
{
294-
return ARRAY_SIZE(plat_sensor_config);
295-
}
292+
const int SENSOR_CONFIG_SIZE = ARRAY_SIZE(plat_sensor_config);
296293

297294
void load_sensor_config(void)
298295
{

‎meta-facebook/yv35-hd/src/platform/plat_sensor_table.c‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,4 @@ bool pal_is_time_to_poll(uint8_t sensor_num, int poll_time)
198198
return true;
199199
}
200200

201-
uint8_t plat_get_config_size()
202-
{
203-
return ARRAY_SIZE(plat_sensor_config);
204-
}
205-
206-
void load_sensor_config(void)
207-
{
208-
memcpy(sensor_config, plat_sensor_config, sizeof(plat_sensor_config));
209-
sensor_config_count = ARRAY_SIZE(plat_sensor_config);
210-
}
201+
const int SENSOR_CONFIG_SIZE = ARRAY_SIZE(plat_sensor_config);

‎meta-facebook/yv35-rf/src/platform/plat_sensor_table.c‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,4 @@ sensor_cfg plat_sensor_config[] = {
151151
&isl69254iraz_t_pre_read_args[0], NULL, NULL, NULL },
152152
};
153153

154-
uint8_t plat_get_config_size()
155-
{
156-
return ARRAY_SIZE(plat_sensor_config);
157-
}
158-
159-
void load_sensor_config(void)
160-
{
161-
memcpy(sensor_config, plat_sensor_config, sizeof(plat_sensor_config));
162-
sensor_config_count = ARRAY_SIZE(plat_sensor_config);
163-
}
154+
const int SENSOR_CONFIG_SIZE = ARRAY_SIZE(plat_sensor_config);

0 commit comments

Comments
 (0)