Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
1 Star 0 Fork 19

chenxun/python

forked from OpenHarmony-SIG/python
Closed
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (1)
master
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
The license selected for the repository is subject to the license used by the main branch of the repository.
master
Branches (1)
master
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (1)
master
python
/
lite-python
/
dev
/
gpio_impl.c
python
/
lite-python
/
dev
/
gpio_impl.c
gpio_impl.c 7.28 KB
Copy Edit Raw Blame History
唐佐林 authored 2021年09月30日 09:30 +08:00 . v0.3.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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
/****************************************************************************
MIT License
Copyright (c) 2021 唐佐林
WeChat : delphi_tang
EMail: delphi_tang@dt4sw.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*****************************************************************************/
#include "gpio_impl.h"
#include "gpio_ex.h"
#define GPIO_IDX_MAX 16
typedef struct
{
int type;
mp_obj_t func;
mp_obj_t arg;
} mp_custom_cb_t;
static volatile mp_custom_cb_t g_callback[GPIO_IDX_MAX] = {0};
static void gpio_callback_func(char* data)
{
int index = (size_t)data;
if( g_callback[index].type )
{
mp_call_function_1(g_callback[index].func, g_callback[index].arg);
}
}
mp_obj_t mp_gpio_init(mp_obj_t idx)
{
return mp_obj_new_int(IoTGpioInit(mp_obj_get_int(idx)));
}
mp_obj_t mp_gpio_deinit(mp_obj_t idx)
{
return mp_obj_new_int(IoTGpioDeinit(mp_obj_get_int(idx)));
}
mp_obj_t mp_gpio_get_dir(mp_obj_t idx)
{
int index = mp_obj_get_int(idx);
IotGpioDir dir = 0;
unsigned int r = IoTGpioGetDir(index, &dir);
mp_obj_t ret[2] =
{
mp_obj_new_int(r),
mp_obj_new_int(dir),
};
return mp_obj_new_tuple(2, ret);
}
mp_obj_t mp_gpio_set_dir(mp_obj_t idx, mp_obj_t dir)
{
int index = mp_obj_get_int(idx);
int direction = mp_obj_get_int(dir);
unsigned int ret = IoTGpioSetDir(index, (IotGpioDir)direction);
return mp_obj_new_int(ret);
}
mp_obj_t mp_gpio_get_output(mp_obj_t idx)
{
int index = mp_obj_get_int(idx);
IotGpioValue val = 0;
unsigned int r = IoTGpioGetOutputVal(index, &val);
mp_obj_t ret[2] =
{
mp_obj_new_int(r),
mp_obj_new_int(val),
};
return mp_obj_new_tuple(2, ret);
}
mp_obj_t mp_gpio_set_output(mp_obj_t idx, mp_obj_t val)
{
int index = mp_obj_get_int(idx);
int value = !!mp_obj_get_int(val);
unsigned int ret = IoTGpioSetOutputVal(index, (IotGpioValue)value);
return mp_obj_new_int(ret);
}
mp_obj_t mp_gpio_get_input(mp_obj_t idx)
{
int index = mp_obj_get_int(idx);
IotGpioValue val = 0;
unsigned int r = IoTGpioGetInputVal(index, &val);
mp_obj_t ret[2] =
{
mp_obj_new_int(r),
mp_obj_new_int(val),
};
return mp_obj_new_tuple(2, ret);
}
mp_obj_t mp_gpio_set_isr_mode(mp_obj_t idx, mp_obj_t mode)
{
int index = mp_obj_get_int(idx);
int type = mp_obj_get_int(mode);
int r = -1;
if( (0 <= index) && (index < GPIO_IDX_MAX) && (0 < type) && (type < GPIO_TYPE_MAX) )
{
IotGpioIntType itype = 0;
IotGpioIntPolarity ipolarity = 0;
switch( type )
{
case GPIO_TYPE_LEVEL_LOW:
itype = IOT_INT_TYPE_LEVEL;
ipolarity = IOT_GPIO_EDGE_FALL_LEVEL_LOW;
break;
case GPIO_TYPE_LEVEL_HIGH:
itype = IOT_INT_TYPE_LEVEL;
ipolarity = IOT_GPIO_EDGE_RISE_LEVEL_HIGH;
break;
case GPIO_TYPE_EDGE_FALL_LOW:
itype = IOT_INT_TYPE_EDGE;
ipolarity = IOT_GPIO_EDGE_FALL_LEVEL_LOW;
break;
case GPIO_TYPE_EDGE_RISE_HIGH:
itype = IOT_INT_TYPE_EDGE;
ipolarity = IOT_GPIO_EDGE_RISE_LEVEL_HIGH;
break;
}
if( (r = IoTGpioSetIsrMode(index, itype, ipolarity)) == 0 )
{
g_callback[index].type = type;
}
}
return mp_obj_new_int(r);
}
mp_obj_t mp_gpio_get_isr_mode(mp_obj_t idx)
{
int index = mp_obj_get_int(idx);
int ret = -1;
if( (0 <= index) && (index < GPIO_IDX_MAX) )
{
ret = g_callback[index].type;
}
return mp_obj_new_int(ret);
}
mp_obj_t mp_gpio_set_isr_mask(mp_obj_t idx, mp_obj_t msk)
{
int index = mp_obj_get_int(idx);
unsigned char mask = (unsigned char)mp_obj_get_int(msk);
int r = IoTGpioSetIsrMask(index, mask);
return mp_obj_new_int(r);
}
mp_obj_t mp_gpio_register_isr_func(mp_obj_t idx, mp_obj_t func, mp_obj_t arg)
{
int index = mp_obj_get_int(idx);
unsigned int r = -1;
const mp_obj_type_t* type = mp_obj_get_type(func);
if( type->call )
{
if( (0 <= index) && (index < GPIO_IDX_MAX) && g_callback[index].type )
{
IotGpioIntType itype = 0;
IotGpioIntPolarity ipolarity = 0;
g_callback[index].func = func;
g_callback[index].arg = arg;
switch( g_callback[index].type )
{
case GPIO_TYPE_LEVEL_LOW:
itype = IOT_INT_TYPE_LEVEL;
ipolarity = IOT_GPIO_EDGE_FALL_LEVEL_LOW;
break;
case GPIO_TYPE_LEVEL_HIGH:
itype = IOT_INT_TYPE_LEVEL;
ipolarity = IOT_GPIO_EDGE_RISE_LEVEL_HIGH;
break;
case GPIO_TYPE_EDGE_FALL_LOW:
itype = IOT_INT_TYPE_EDGE;
ipolarity = IOT_GPIO_EDGE_FALL_LEVEL_LOW;
break;
case GPIO_TYPE_EDGE_RISE_HIGH:
itype = IOT_INT_TYPE_EDGE;
ipolarity = IOT_GPIO_EDGE_RISE_LEVEL_HIGH;
break;
}
r = IoTGpioRegisterIsrFunc(index, itype, ipolarity, gpio_callback_func, (char*)(size_t)index);
}
}
else
{
mp_raise_TypeError(MP_ERROR_TEXT("func is not callable"));
}
return mp_obj_new_int(r);
}
mp_obj_t mp_gpio_unregister_isr_func(mp_obj_t idx)
{
int index = mp_obj_get_int(idx);
unsigned int r = -1;
if( (0 <= index) && (index < GPIO_IDX_MAX) )
{
g_callback[index].type = 0;
r = IoTGpioUnregisterIsrFunc(index);
}
return mp_obj_new_int(r);
}
mp_obj_t mp_gpio_set_pull(mp_obj_t idx, mp_obj_t val)
{
return mp_obj_new_int(DTGpioSetPull(mp_obj_get_int(idx), mp_obj_get_int(val)));
}
mp_obj_t mp_gpio_set_func(mp_obj_t idx, mp_obj_t val)
{
return mp_obj_new_int(DTGpioSetFunc(mp_obj_get_int(idx), mp_obj_get_int(val)));
}
mp_obj_t mp_gpio_query_pull_value(mp_obj_t key)
{
return mp_obj_new_int(gpio_query_pull_value(mp_obj_str_get_str(key)));
}
mp_obj_t mp_gpio_query_func_value(mp_obj_t idx, mp_obj_t key)
{
return mp_obj_new_int(gpio_query_func_value(mp_obj_get_int(idx), mp_obj_str_get_str(key)));
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chenxun074/python.git
git@gitee.com:chenxun074/python.git
chenxun074
python
python
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /