blob: f2cc623262494865bd9b3bca3b772b92e033d295 [file] [log] [blame]
Alex Ray09875a22013-09-04 23:32:55 -07001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#define LOG_TAG "ConsumerIrHal"
17
18#include <errno.h>
Elliott Hughes07c08552015-01-29 21:19:10 -080019#include <malloc.h>
Mark Salyzynd88dfe82017-04-11 08:56:09 -070020#include <stdlib.h>
Alex Ray09875a22013-09-04 23:32:55 -070021#include <string.h>
Mark Salyzynd88dfe82017-04-11 08:56:09 -070022#include <unistd.h>
23
24#include <log/log.h>
25
Alex Ray09875a22013-09-04 23:32:55 -070026#include <hardware/consumerir.h>
Mark Salyzynd88dfe82017-04-11 08:56:09 -070027#include <hardware/hardware.h>
Alex Ray09875a22013-09-04 23:32:55 -070028
Chih-Hung Hsieh4d52b432016-05-12 10:07:30 -070029#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
Alex Ray09875a22013-09-04 23:32:55 -070030
31static const consumerir_freq_range_t consumerir_freqs[] = {
32 {.min = 30000, .max = 30000},
33 {.min = 33000, .max = 33000},
34 {.min = 36000, .max = 36000},
35 {.min = 38000, .max = 38000},
36 {.min = 40000, .max = 40000},
37 {.min = 56000, .max = 56000},
38};
39
Glenn Kasten6c2a68d2014-07-15 11:11:01 -070040static int consumerir_transmit(struct consumerir_device *dev __unused,
41 int carrier_freq, const int pattern[], int pattern_len)
Alex Ray09875a22013-09-04 23:32:55 -070042{
43 int total_time = 0;
44 long i;
45
46 for (i = 0; i < pattern_len; i++)
47 total_time += pattern[i];
48
49 /* simulate the time spent transmitting by sleeping */
50 ALOGD("transmit for %d uS at %d Hz", total_time, carrier_freq);
51 usleep(total_time);
52
53 return 0;
54}
55
Glenn Kasten6c2a68d2014-07-15 11:11:01 -070056static int consumerir_get_num_carrier_freqs(struct consumerir_device *dev __unused)
Alex Ray09875a22013-09-04 23:32:55 -070057{
58 return ARRAY_SIZE(consumerir_freqs);
59}
60
Glenn Kasten6c2a68d2014-07-15 11:11:01 -070061static int consumerir_get_carrier_freqs(struct consumerir_device *dev __unused,
Alex Rayd9d105a2013-09-11 16:20:07 -070062 size_t len, consumerir_freq_range_t *ranges)
Alex Ray09875a22013-09-04 23:32:55 -070063{
Alex Rayd9d105a2013-09-11 16:20:07 -070064 size_t to_copy = ARRAY_SIZE(consumerir_freqs);
65
66 to_copy = len < to_copy ? len : to_copy;
67 memcpy(ranges, consumerir_freqs, to_copy * sizeof(consumerir_freq_range_t));
68 return to_copy;
Alex Ray09875a22013-09-04 23:32:55 -070069}
70
71static int consumerir_close(hw_device_t *dev)
72{
73 free(dev);
74 return 0;
75}
76
77/*
78 * Generic device handling
79 */
80static int consumerir_open(const hw_module_t* module, const char* name,
81 hw_device_t** device)
82{
83 if (strcmp(name, CONSUMERIR_TRANSMITTER) != 0) {
84 return -EINVAL;
85 }
86 if (device == NULL) {
87 ALOGE("NULL device on open");
88 return -EINVAL;
89 }
90
91 consumerir_device_t *dev = malloc(sizeof(consumerir_device_t));
92 memset(dev, 0, sizeof(consumerir_device_t));
93
94 dev->common.tag = HARDWARE_DEVICE_TAG;
95 dev->common.version = 0;
96 dev->common.module = (struct hw_module_t*) module;
97 dev->common.close = consumerir_close;
98
99 dev->transmit = consumerir_transmit;
100 dev->get_num_carrier_freqs = consumerir_get_num_carrier_freqs;
101 dev->get_carrier_freqs = consumerir_get_carrier_freqs;
102
103 *device = (hw_device_t*) dev;
104 return 0;
105}
106
107static struct hw_module_methods_t consumerir_module_methods = {
108 .open = consumerir_open,
109};
110
111consumerir_module_t HAL_MODULE_INFO_SYM = {
112 .common = {
113 .tag = HARDWARE_MODULE_TAG,
114 .module_api_version = CONSUMERIR_MODULE_API_VERSION_1_0,
115 .hal_api_version = HARDWARE_HAL_API_VERSION,
116 .id = CONSUMERIR_HARDWARE_MODULE_ID,
117 .name = "Demo IR HAL",
118 .author = "The Android Open Source Project",
119 .methods = &consumerir_module_methods,
120 },
121};