mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
add PikaVSF package
This commit is contained in:
parent
cfee803e4c
commit
30c122eecd
24
package/PikaVSF/PikaVSF.py
Normal file
24
package/PikaVSF/PikaVSF.py
Normal file
@ -0,0 +1,24 @@
|
||||
import PikaStdDevice
|
||||
|
||||
// kernel
|
||||
// TODO
|
||||
|
||||
// hal
|
||||
class GPIO(PikaStdDevice.GPIO):
|
||||
def platformHigh():
|
||||
pass
|
||||
|
||||
def platformLow():
|
||||
pass
|
||||
|
||||
def platformEnable():
|
||||
pass
|
||||
|
||||
def platformDisable():
|
||||
pass
|
||||
|
||||
def platformSetMode():
|
||||
pass
|
||||
|
||||
def platformRead():
|
||||
pass
|
63
package/PikaVSF/PikaVSF_GPIO.c
Normal file
63
package/PikaVSF/PikaVSF_GPIO.c
Normal file
@ -0,0 +1,63 @@
|
||||
#include "pika_config.h"
|
||||
#include "PikaObj.h"
|
||||
|
||||
#if VSF_HAL_USE_GPIO == ENABLED && GPIO_COUNT > 0
|
||||
# define __PIKA_VSF_GPIO ENABLED
|
||||
#endif
|
||||
|
||||
#if __PIKA_VSF_GPIO == ENABLED
|
||||
static int __vsf_gpio_pin_get(char *pin) {
|
||||
int hw_port = 0, hw_pin = 0;
|
||||
return vsf_hw_io_mapper_pin(hw_port, hw_pin);
|
||||
}
|
||||
#endif
|
||||
|
||||
void PikaVSF_GPIO_platformEnable(PikaObj *self) {
|
||||
|
||||
}
|
||||
void PikaVSF_GPIO_platformDisable(PikaObj *self) {
|
||||
|
||||
}
|
||||
void PikaVSF_GPIO_platformHigh(PikaObj *self) {
|
||||
#if __PIKA_VSF_GPIO == ENABLED
|
||||
char *pin = obj_getStr(self, "pin");
|
||||
int pin_idx = __vsf_gpio_pin_get(pin);
|
||||
vsf_io_mapper_set(&vsf_hw_io_mapper, pin_idx);
|
||||
#else
|
||||
vsf_trace_error("%s: platform has no gpio or gpio is disabled" VSF_TRACE_CFG_LINEEND);
|
||||
#endif
|
||||
}
|
||||
void PikaVSF_GPIO_platformLow(PikaObj *self) {
|
||||
#if __PIKA_VSF_GPIO == ENABLED
|
||||
char *pin = obj_getStr(self, "pin");
|
||||
int pin_idx = __vsf_gpio_pin_get(pin);
|
||||
vsf_io_mapper_clear(&vsf_hw_io_mapper, pin_idx);
|
||||
#else
|
||||
vsf_trace_error("%s: platform has no gpio or gpio is disabled" VSF_TRACE_CFG_LINEEND);
|
||||
#endif
|
||||
}
|
||||
void PikaVSF_GPIO_platformRead(PikaObj *self) {
|
||||
#if __PIKA_VSF_GPIO == ENABLED
|
||||
char *pin = obj_getStr(self, "pin");
|
||||
int pin_idx = __vsf_gpio_pin_get(pin);
|
||||
int pin_value = vsf_io_mapper_read(&vsf_hw_io_mapper, pin_idx);
|
||||
obj_setInt(self, "readBuff", pin_value);
|
||||
#else
|
||||
vsf_trace_error("%s: platform has no gpio or gpio is disabled" VSF_TRACE_CFG_LINEEND);
|
||||
#endif
|
||||
}
|
||||
void PikaVSF_GPIO_platformSetMode(PikaObj *self) {
|
||||
#if __PIKA_VSF_GPIO == ENABLED
|
||||
char *pin = obj_getStr(self, "pin");
|
||||
char *mode = obj_getStr(self, "mode");
|
||||
int pin_idx = __vsf_gpio_pin_get(pin);
|
||||
|
||||
if (strEqu(mode, "out")) {
|
||||
vsf_io_mapper_set_output(&vsf_hw_io_mapper, pin_idx);
|
||||
} else if (strEqu(mode, "in")) {
|
||||
vsf_io_mapper_set_input(&vsf_hw_io_mapper, pin_idx);
|
||||
}
|
||||
#else
|
||||
vsf_trace_error("%s: platform has no gpio or gpio is disabled" VSF_TRACE_CFG_LINEEND);
|
||||
#endif
|
||||
}
|
61
package/PikaVSF/pika_config.c
Normal file
61
package/PikaVSF/pika_config.c
Normal file
@ -0,0 +1,61 @@
|
||||
/*****************************************************************************
|
||||
* Copyright(C)2009-2019 by VSF Team *
|
||||
* *
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); *
|
||||
* you may not use this file except in compliance with the License. *
|
||||
* You may obtain a copy of the License at *
|
||||
* *
|
||||
* http://www.apache.org/licenses/LICENSE-2.0 *
|
||||
* *
|
||||
* Unless required by applicable law or agreed to in writing, software *
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, *
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
|
||||
* See the License for the specific language governing permissions and *
|
||||
* limitations under the License. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
|
||||
/*============================ INCLUDES ======================================*/
|
||||
|
||||
#include "pika_config.h"
|
||||
#include "PikaPlatform.h"
|
||||
|
||||
/*============================ MACROS ========================================*/
|
||||
|
||||
#if VSF_USE_HEAP != ENABLED
|
||||
# error "Please enable VSF_USE_HEAP"
|
||||
#endif
|
||||
|
||||
/*============================ MACROFIED FUNCTIONS ===========================*/
|
||||
/*============================ TYPES =========================================*/
|
||||
/*============================ GLOBAL VARIABLES ==============================*/
|
||||
/*============================ LOCAL VARIABLES ===============================*/
|
||||
|
||||
static unsigned int __crit_cnt = 0U;
|
||||
static vsf_arch_prio_t __crit_saved = 0U;
|
||||
|
||||
/*============================ PROTOTYPES ====================================*/
|
||||
/*============================ IMPLEMENTATION ================================*/
|
||||
|
||||
void __platform_disable_irq_handle(void)
|
||||
{
|
||||
if (0U == __crit_cnt) {
|
||||
__crit_saved = vsf_disable_interrupt();
|
||||
}
|
||||
__crit_cnt++;
|
||||
}
|
||||
|
||||
void __platform_enable_irq_handle(void)
|
||||
{
|
||||
__crit_cnt--;
|
||||
if (0U == __crit_cnt) {
|
||||
vsf_set_interrupt(__crit_saved);
|
||||
}
|
||||
}
|
||||
|
||||
void * __platform_malloc(size_t size) {
|
||||
return vsf_heap_malloc(size);
|
||||
}
|
||||
void __platform_free(void* ptr) {
|
||||
vsf_heap_free(ptr);
|
||||
}
|
23
package/PikaVSF/pika_config.h
Normal file
23
package/PikaVSF/pika_config.h
Normal file
@ -0,0 +1,23 @@
|
||||
/*****************************************************************************
|
||||
* Copyright(C)2009-2019 by VSF Team *
|
||||
* *
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); *
|
||||
* you may not use this file except in compliance with the License. *
|
||||
* You may obtain a copy of the License at *
|
||||
* *
|
||||
* http://www.apache.org/licenses/LICENSE-2.0 *
|
||||
* *
|
||||
* Unless required by applicable law or agreed to in writing, software *
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, *
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
|
||||
* See the License for the specific language governing permissions and *
|
||||
* limitations under the License. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __VSF_PIKA_PORT_H__
|
||||
#define __VSF_PIKA_PORT_H__
|
||||
|
||||
#include "vsf.h"
|
||||
|
||||
#endif // __VSF_PIKA_PORT_H__
|
Loading…
x
Reference in New Issue
Block a user