11 changed files with 238 additions and 10 deletions
-
9chip/basic/basic_h/marco.h
-
63chip/basic/chip_helper.cpp
-
4chip/basic/chip_helper.hpp
-
3chip/basic/clock.cpp
-
10chip/chip.cpp
-
9chip/chip.hpp
-
2chip/zgpio.cpp
-
79components/key_monitor/zkey_service.cpp
-
65components/key_monitor/zkey_service.hpp
-
2os/os_default_schduler.cpp
-
2os/os_default_schduler.hpp
@ -1,18 +1,19 @@ |
|||
#pragma once
|
|||
|
|||
#include "chip_tim_irq_shceduler.hpp"
|
|||
#include "zirq_dispatcher.hpp"
|
|||
#include "zcan_irq_dispatcher.hpp"
|
|||
#include "zgpio.hpp"
|
|||
#include "zirq_dispatcher.hpp"
|
|||
#include "ztim.hpp"
|
|||
#include "zuart.hpp"
|
|||
|
|||
extern "C" { |
|||
|
|||
typedef struct { |
|||
zchip_tim_t *us_dleay_tim; |
|||
zchip_tim_t *tim_irq_scheduler_tim; |
|||
zchip_uart_t *huart; |
|||
zchip_tim_t *us_dleay_tim; |
|||
zchip_tim_t *tim_irq_scheduler_tim; |
|||
zchip_uart_t *huart; |
|||
iflytop::ZGPIO *debuglight; |
|||
} chip_cfg_t; |
|||
|
|||
void chip_init(chip_cfg_t *cfg); |
@ -0,0 +1,79 @@ |
|||
#include "zkey_service.hpp"
|
|||
using namespace iflytop; |
|||
#define TAG "ZKeyService"
|
|||
/*******************************************************************************
|
|||
* KEY * |
|||
*******************************************************************************/ |
|||
ZKey::ZKey(int id, Pin_t pin, ZGPIO::GPIOMode_t mode, ZGPIO::GPIOIrqType_t irqtype, bool mirror) { |
|||
this->id = id; |
|||
this->pin = pin; |
|||
this->mode = mode; |
|||
this->irqtype = irqtype; |
|||
this->mirror = mirror; |
|||
} |
|||
ZKey::~ZKey() {} |
|||
|
|||
void ZKey::init() { gpio.initAsInput(pin, mode, irqtype, mirror); } |
|||
void ZKey::setHasProcessed(bool hasProcessed) { this->hasProcessed = hasProcessed; } |
|||
bool ZKey::isHasProcessed() { return hasProcessed; } |
|||
int ZKey::getId() { return id; } |
|||
|
|||
/*******************************************************************************
|
|||
* ZKeyService * |
|||
*******************************************************************************/ |
|||
|
|||
void ZKeyService::initialize(ZKey* keys, int numKey, KeyListener_t listener) { |
|||
m_keys = keys; |
|||
ZASSERT(m_keys != NULL); |
|||
this->m_numKey = numKey; |
|||
m_listener = listener; |
|||
m_lastcallticket = 0; |
|||
|
|||
for (int i = 0; i < m_numKey; i++) { |
|||
m_keys[i].init(); |
|||
} |
|||
} |
|||
|
|||
void ZKeyService::processEachAfterFilter(ZKey* each, bool now_io_state) { |
|||
if (now_io_state != each->last_after_filter_io_state) { |
|||
if (now_io_state) { |
|||
each->keep_state_count = 0; |
|||
each->hasProcessed = false; |
|||
m_listener(each, zke_rising_edge); |
|||
} else { |
|||
m_listener(each, zke_falling_edge); |
|||
each->keep_state_count = 0; |
|||
} |
|||
each->last_after_filter_io_state = now_io_state; |
|||
} else { |
|||
if (now_io_state) { |
|||
m_listener(each, zke_keep); |
|||
} |
|||
} |
|||
} |
|||
|
|||
void ZKeyService::processKey(ZKey* each) { |
|||
/**
|
|||
* @brief zkey_process_each |
|||
*/ |
|||
each->keep_state_count++; |
|||
|
|||
bool now_io_state = each->gpio.getState(); |
|||
if (each->currentstatekeep_count < 1000) { |
|||
each->currentstatekeep_count++; |
|||
} |
|||
if (now_io_state != each->last_io_state) { |
|||
each->currentstatekeep_count = 0; |
|||
} |
|||
if (each->currentstatekeep_count >= 1) { |
|||
each->after_filter_state = now_io_state; |
|||
} |
|||
each->last_io_state = now_io_state; |
|||
processEachAfterFilter(each, each->after_filter_state); |
|||
} |
|||
|
|||
void ZKeyService::periodicJob() { |
|||
for (int i = 0; i < m_numKey; i++) { |
|||
processKey(&m_keys[i]); |
|||
} |
|||
} |
@ -0,0 +1,65 @@ |
|||
#pragma once
|
|||
#include <stdint.h>
|
|||
|
|||
#include "sdk/os/zos.hpp"
|
|||
namespace iflytop { |
|||
using namespace std; |
|||
class ZKeyService; |
|||
|
|||
class ZKey { |
|||
private: |
|||
/* data */ |
|||
int id; |
|||
Pin_t pin; |
|||
ZGPIO::GPIOMode_t mode; |
|||
ZGPIO::GPIOIrqType_t irqtype; |
|||
bool mirror; |
|||
|
|||
ZGPIO gpio; |
|||
|
|||
bool last_io_state; |
|||
bool last_after_filter_io_state; |
|||
uint32_t keep_state_count; |
|||
bool after_filter_state; |
|||
uint32_t currentstatekeep_count; |
|||
|
|||
bool hasProcessed; /*useful for user*/ |
|||
public: |
|||
friend class ZKeyService; |
|||
ZKey(int id, Pin_t pin, ZGPIO::GPIOMode_t mode, ZGPIO::GPIOIrqType_t irqtype, bool mirror); |
|||
~ZKey(); |
|||
|
|||
void init(); |
|||
|
|||
void setHasProcessed(bool hasProcessed); |
|||
bool isHasProcessed(); |
|||
int getId(); |
|||
}; |
|||
|
|||
class ZKeyService { |
|||
public: |
|||
typedef enum { |
|||
zke_keep, |
|||
zke_rising_edge, |
|||
zke_falling_edge, |
|||
} KeyEvent_t; |
|||
|
|||
typedef function<void(ZKey* key, KeyEvent_t event)> KeyListener_t; |
|||
|
|||
private: |
|||
/* data */ |
|||
ZKey* m_keys; |
|||
int m_numKey; |
|||
KeyListener_t m_listener; |
|||
uint32_t m_lastcallticket; |
|||
|
|||
public: |
|||
void initialize(ZKey* keys, int numKey, KeyListener_t listener); |
|||
void periodicJob(); |
|||
|
|||
private: |
|||
void processKey(ZKey* each); |
|||
void processEachAfterFilter(ZKey* each, bool now_io_state); |
|||
}; |
|||
|
|||
} // namespace iflytop
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue