Skip to content

Commit 30d8dad

Browse files
committed
More ESP32-S3 stuff.
1 parent b7d4c02 commit 30d8dad

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

SerialPrograms/Source/Controllers/Controller.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class AbstractController{
5454

5555
// The minimum amount of time between two state reports. This effectively
5656
// limits how quickly you can change states.
57+
// Controllers with non-zero ticksize will have (ticksize == cooldown).
5758
virtual Milliseconds cooldown() const = 0;
5859

5960
// Some controllers are imprecise. This returns the variation.

SerialPrograms/Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_PokkenController.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ void SerialPABotBase_PokkenController::push_state(const Cancellable* cancellable
183183
// This loop can block indefinitely if the command queue is full.
184184
ReverseLockGuard<std::mutex> lg(m_state_lock);
185185

186-
// Divide the controller state into smaller chunks of 255 ticks.
186+
// Divide the controller state into smaller chunks that fit into the report
187+
// duration.
187188
Milliseconds time_left = std::chrono::duration_cast<Milliseconds>(duration);
188189

189190
if (m_use_milliseconds){
@@ -221,6 +222,32 @@ void SerialPABotBase_PokkenController::push_state(const Cancellable* cancellable
221222
}
222223

223224

225+
//
226+
// Given a regularly reported 32-bit counter that wraps around, infer its true
227+
// 64-bit value.
228+
//
229+
class ExtendedLengthCounter{
230+
public:
231+
ExtendedLengthCounter()
232+
: m_high_bits(0)
233+
, m_last_received(0)
234+
{}
235+
236+
uint64_t push_short_value(uint32_t counter){
237+
if (counter < m_last_received && counter - m_last_received < 0x40000000){
238+
m_high_bits++;
239+
}
240+
m_last_received = counter;
241+
return ((uint64_t)m_high_bits << 32) | counter;
242+
}
243+
244+
private:
245+
uint32_t m_high_bits;
246+
uint32_t m_last_received;
247+
};
248+
249+
250+
224251
void SerialPABotBase_PokkenController::status_thread(){
225252
constexpr std::chrono::milliseconds PERIOD(1000);
226253
std::atomic<WallClock> last_ack(current_time());
@@ -255,6 +282,8 @@ void SerialPABotBase_PokkenController::status_thread(){
255282
}
256283
});
257284

285+
286+
ExtendedLengthCounter clock_tracker;
258287
WallClock next_ping = current_time();
259288
while (true){
260289
if (m_stopping.load(std::memory_order_relaxed) || !m_handle.is_ready()){
@@ -269,7 +298,8 @@ void SerialPABotBase_PokkenController::status_thread(){
269298
&m_scope
270299
).convert<PABB_MSG_ACK_REQUEST_I32>(logger(), response);
271300
last_ack.store(current_time(), std::memory_order_relaxed);
272-
uint32_t wallclock = response.data;
301+
uint64_t wallclock = clock_tracker.push_short_value(response.data);
302+
273303
if (wallclock == 0){
274304
m_handle.set_status_line1(
275305
"Not connected to Switch.",

SerialPrograms/Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_PokkenController.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ class SerialPABotBase_PokkenController final :
5555
}
5656

5757
virtual Milliseconds ticksize() const override{
58-
return Milliseconds(8);
58+
return m_use_milliseconds ? Milliseconds(0) : Milliseconds(8);
5959
}
6060
virtual Milliseconds cooldown() const override{
61-
return Milliseconds(8);
61+
return m_use_milliseconds ? Milliseconds(0) : Milliseconds(8);
6262
}
6363
virtual Milliseconds timing_variation() const override{
6464
return ConsoleSettings::instance().TIMING_OPTIONS.WIRED_MICROCONTROLLER;

0 commit comments

Comments
 (0)