mirror of
https://github.com/espruino/Espruino.git
synced 2025-12-08 19:06:15 +00:00
Revert "Fix build issues, remove duplication"
This reverts commit 3007686199ec02d3e727ce918a551c0e9e8a3b75.
This commit is contained in:
parent
2480890f3c
commit
ad34e66d88
@ -11,10 +11,9 @@
|
||||
* Hardware interface Layer common functions
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
#include "platform_config.h"
|
||||
#include "jshardware.h"
|
||||
#include "jsinteractive.h"
|
||||
#include "jstimer.h"
|
||||
#include "platform_config.h"
|
||||
|
||||
void jshUSARTInitInfo(JshUSARTInfo *inf) {
|
||||
inf->baudRate = DEFAULT_BAUD_RATE;
|
||||
@ -125,28 +124,3 @@ __attribute__((weak)) void jshBusyIdle() {
|
||||
__attribute__((weak)) bool jshIsPinStateDefault(Pin pin, JshPinState state) {
|
||||
return state == JSHPINSTATE_GPIO_IN || state == JSHPINSTATE_ADC_IN;
|
||||
}
|
||||
|
||||
// Only define this if it's not used elsewhere. Currently everything except Linux (which has no util timer) uses this
|
||||
__attribute__((weak)) void jshPinPulse(Pin pin, bool pulsePolarity, JsVarFloat pulseTime) {
|
||||
// ---- USE TIMER FOR PULSE
|
||||
if (!jshIsPinValid(pin)) {
|
||||
jsExceptionHere(JSET_ERROR, "Invalid pin!");
|
||||
return;
|
||||
}
|
||||
if (pulseTime<=0) {
|
||||
// just wait for everything to complete
|
||||
jstUtilTimerWaitEmpty();
|
||||
return;
|
||||
} else {
|
||||
// find out if we already had a timer scheduled
|
||||
UtilTimerTask task;
|
||||
if (!jstGetLastPinTimerTask(pin, &task)) {
|
||||
// no timer - just start the pulse now!
|
||||
jshPinOutput(pin, pulsePolarity);
|
||||
task.timeLeft = 0;
|
||||
}
|
||||
// Now set the end of the pulse to happen on a timer
|
||||
jstPinOutputAtTime(jshGetSystemTime() + task.timeLeft + jshGetTimeFromMilliseconds(pulseTime), &pin, 1, !pulsePolarity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -217,9 +217,6 @@ eg. `digitalPulse(A0,1,5);` pulses A0 high for 5ms. `digitalPulse(A0,1,[5,2,4]);
|
||||
digitalPulse is for SHORT pulses that need to be very accurate. If you're doing anything over a few milliseconds, use setTimeout instead.
|
||||
*/
|
||||
void jswrap_io_digitalPulse(Pin pin, bool value, JsVar *times) {
|
||||
// TODO: We should use jstPinOutputAtTime directly and delete jshPinPulse
|
||||
// - it's inefficient and also causes issues as the RTC changes while we're
|
||||
// trying to add items to the timer list
|
||||
if (jsvIsNumeric(times)) {
|
||||
JsVarFloat time = jsvGetFloat(times);
|
||||
if (time<0 || isnan(time)) {
|
||||
|
||||
@ -147,6 +147,9 @@ JshPinFunction jshPinAnalogOutput(Pin pin, JsVarFloat value, JsVarFloat freq, Js
|
||||
return JSH_NOTHING;
|
||||
}
|
||||
|
||||
void jshPinPulse(Pin pin, bool value, JsVarFloat time) {
|
||||
}
|
||||
|
||||
bool jshCanWatch(Pin pin) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -431,6 +431,43 @@ bool CALLED_FROM_INTERRUPT jshGetWatchedPinState(IOEventFlags eventFlag) { // ca
|
||||
return level;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the value of the pin to be the value supplied and then wait for
|
||||
* a given period and set the pin value again to be the opposite.
|
||||
*/
|
||||
void jshPinPulse(
|
||||
Pin pin, //!< The pin to be pulsed.
|
||||
bool pulsePolarity, //!< The value to be pulsed into the pin.
|
||||
JsVarFloat pulseTime //!< The duration in milliseconds to hold the pin.
|
||||
) {
|
||||
// ESP32 specific version, replaced by Espruino Style version from nrf52
|
||||
//int duration = (int)pulseTime * 1000; //from millisecs to microsecs
|
||||
//sendPulse(pin, pulsePolarity, duration);
|
||||
|
||||
// ---- USE TIMER FOR PULSE
|
||||
if (!jshIsPinValid(pin)) {
|
||||
jsExceptionHere(JSET_ERROR, "Invalid pin!");
|
||||
return;
|
||||
}
|
||||
if (pulseTime<=0) {
|
||||
// just wait for everything to complete
|
||||
jstUtilTimerWaitEmpty();
|
||||
return;
|
||||
} else {
|
||||
// find out if we already had a timer scheduled
|
||||
UtilTimerTask task;
|
||||
if (!jstGetLastPinTimerTask(pin, &task)) {
|
||||
// no timer - just start the pulse now!
|
||||
jshPinOutput(pin, pulsePolarity);
|
||||
task.time = jshGetSystemTime();
|
||||
}
|
||||
// Now set the end of the pulse to happen on a timer
|
||||
jstPinOutputAtTime(task.time + jshGetTimeFromMilliseconds(pulseTime), &pin, 1, !pulsePolarity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether the pin can be watchable.
|
||||
* \return Returns true if the pin is watchable.
|
||||
|
||||
@ -672,6 +672,38 @@ bool CALLED_FROM_INTERRUPT jshGetWatchedPinState(IOEventFlags eventFlag) { // ca
|
||||
return currentPinValue;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the value of the pin to be the value supplied and then wait for
|
||||
* a given period and set the pin value again to be the opposite.
|
||||
*/
|
||||
void jshPinPulse(
|
||||
Pin pin, //!< The pin to be pulsed.
|
||||
bool pulsePolarity, //!< The value to be pulsed into the pin.
|
||||
JsVarFloat pulseTime //!< The duration in milliseconds to hold the pin.
|
||||
) {
|
||||
|
||||
if (!jshIsPinValid(pin)) {
|
||||
jsExceptionHere(JSET_ERROR, "Invalid pin!");
|
||||
return;
|
||||
}
|
||||
if (pulseTime <= 0) {
|
||||
// just wait for everything to complete [??? what does this mean ???]
|
||||
jstUtilTimerWaitEmpty();
|
||||
return;
|
||||
} else {
|
||||
// find out if we already had a timer scheduled
|
||||
UtilTimerTask task;
|
||||
if (!jstGetLastPinTimerTask(pin, &task)) {
|
||||
// no timer - just start the pulse now!
|
||||
jshPinOutput(pin, pulsePolarity);
|
||||
task.time = jshGetSystemTime();
|
||||
}
|
||||
// Now set the end of the pulse to happen on a timer
|
||||
jstPinOutputAtTime(task.time + jshGetTimeFromMilliseconds(pulseTime), &pin, 1, !pulsePolarity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the pin can be watchable.
|
||||
* \return Returns true if the pin is wathchable.
|
||||
|
||||
@ -578,7 +578,6 @@ JshPinFunction jshPinAnalogOutput(Pin pin, JsVarFloat value, JsVarFloat freq, Js
|
||||
return JSH_NOTHING;
|
||||
}
|
||||
|
||||
// Override built-in jshPinPulse as we have no util timer
|
||||
void jshPinPulse(Pin pin, bool value, JsVarFloat time) {
|
||||
if (jshIsPinValid(pin)) {
|
||||
jshPinSetState(pin, JSHPINSTATE_GPIO_OUT);
|
||||
|
||||
@ -1382,6 +1382,30 @@ void jshSetOutputValue(JshPinFunction func, int value) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void jshPinPulse(Pin pin, bool pulsePolarity, JsVarFloat pulseTime) {
|
||||
// ---- USE TIMER FOR PULSE
|
||||
if (!jshIsPinValid(pin)) {
|
||||
jsExceptionHere(JSET_ERROR, "Invalid pin!");
|
||||
return;
|
||||
}
|
||||
if (pulseTime<=0) {
|
||||
// just wait for everything to complete
|
||||
jstUtilTimerWaitEmpty();
|
||||
return;
|
||||
} else {
|
||||
// find out if we already had a timer scheduled
|
||||
UtilTimerTask task;
|
||||
if (!jstGetLastPinTimerTask(pin, &task)) {
|
||||
// no timer - just start the pulse now!
|
||||
jshPinOutput(pin, pulsePolarity);
|
||||
task.timeLeft = 0;
|
||||
}
|
||||
// Now set the end of the pulse to happen on a timer
|
||||
jstPinOutputAtTime(jshGetSystemTime() + task.timeLeft + jshGetTimeFromMilliseconds(pulseTime), &pin, 1, !pulsePolarity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static IOEventFlags jshGetEventFlagsForWatchedPin(nrf_drv_gpiote_pin_t pin) {
|
||||
uint32_t addr = nrf_drv_gpiote_in_event_addr_get(pin);
|
||||
// sigh. all because the right stuff isn't exported. All we wanted was channel_port_get
|
||||
|
||||
@ -2711,6 +2711,30 @@ void jshUtilTimerStart(JsSysTime period) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void jshPinPulse(Pin pin, bool pulsePolarity, JsVarFloat pulseTime) {
|
||||
// ---- USE TIMER FOR PULSE
|
||||
if (!jshIsPinValid(pin)) {
|
||||
jsExceptionHere(JSET_ERROR, "Invalid pin!");
|
||||
return;
|
||||
}
|
||||
if (pulseTime<=0) {
|
||||
// just wait for everything to complete
|
||||
jstUtilTimerWaitEmpty();
|
||||
return;
|
||||
} else {
|
||||
// find out if we already had a timer scheduled
|
||||
UtilTimerTask task;
|
||||
if (!jstGetLastPinTimerTask(pin, &task)) {
|
||||
// no timer - just start the pulse now!
|
||||
jshPinOutput(pin, pulsePolarity);
|
||||
task.time = jshGetSystemTime();
|
||||
}
|
||||
// Now set the end of the pulse to happen on a timer
|
||||
jstPinOutputAtTime(task.time + jshGetTimeFromMilliseconds(pulseTime), &pin, 1, !pulsePolarity);
|
||||
}
|
||||
}
|
||||
|
||||
JshPinFunction jshGetCurrentPinFunction(Pin pin) {
|
||||
// FIXME: This isn't actually right - we need to look at the hardware or store this info somewhere.
|
||||
if (jshIsPinValid(pin)) {
|
||||
|
||||
@ -1481,6 +1481,31 @@ JshPinFunction jshPinAnalogOutput(Pin pin, JsVarFloat value, JsVarFloat freq, Js
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// Pulse a pin for a certain time, but via IRQs, not JS: `digitalWrite(pin,value);setTimeout("digitalWrite(pin,!value)", time*1000);`
|
||||
void jshPinPulse(Pin pin, bool pulsePolarity, JsVarFloat pulseTime){
|
||||
// ---- USE TIMER FOR PULSE
|
||||
if (!jshIsPinValid(pin)) {
|
||||
jsExceptionHere(JSET_ERROR, "Invalid pin!");
|
||||
return;
|
||||
}
|
||||
if (pulseTime<=0) {
|
||||
// just wait for everything to complete
|
||||
jstUtilTimerWaitEmpty();
|
||||
return;
|
||||
} else {
|
||||
// find out if we already had a timer scheduled
|
||||
UtilTimerTask task;
|
||||
if (!jstGetLastPinTimerTask(pin, &task)) {
|
||||
// no timer - just start the pulse now!
|
||||
jshPinOutput(pin, pulsePolarity);
|
||||
task.time = jshGetSystemTime();
|
||||
}
|
||||
// Now set the end of the pulse to happen on a timer
|
||||
jstPinOutputAtTime(task.time + jshGetTimeFromMilliseconds(pulseTime), &pin, 1, !pulsePolarity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// Can the given pin be watched? it may not be possible because of conflicts
|
||||
bool jshCanWatch(Pin pin){
|
||||
if (jshIsPinValid(pin)) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user