<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Modifying the nPM1300 one button example</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/110205/modifying-the-npm1300-one-button-example</link><description>Hi. 
 I want to modify the &amp;quot;nPM1300 One Button&amp;quot; example. 
 I need the Ship mode to be activated after pressing and holding the SHPHLD button for longer than 3 seconds. The Ship mode should activate before I release the SHPHLD button. 
 I plan to implement</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 18 Apr 2024 08:29:12 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/110205/modifying-the-npm1300-one-button-example" /><item><title>RE: Modifying the nPM1300 one button example</title><link>https://devzone.nordicsemi.com/thread/479357?ContentTypeID=1</link><pubDate>Thu, 18 Apr 2024 08:29:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2f491b5a-0416-442c-8085-99ee1c08f3e0</guid><dc:creator>backstreet.devisor</dc:creator><description>&lt;p&gt;Hi. Thanks Andy.&lt;/p&gt;
[quote userid="128887" url="~/f/nordic-q-a/110205/modifying-the-npm1300-one-button-example/479338"]Is there a particular reason you would like to go to ship before the button is released?[/quote]
&lt;p&gt;I just think it would be more convenient from an end user perspective. All you have to do is press a button and just wait for the device to turn off, without having to think about the timing of the press and when to release the button (&amp;gt;5 seconds as in the default example). &lt;br /&gt;But that&amp;#39;s just my personal opinion))&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Modifying the nPM1300 one button example</title><link>https://devzone.nordicsemi.com/thread/479338?ContentTypeID=1</link><pubDate>Thu, 18 Apr 2024 06:52:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0f36e8fc-a084-4c5c-8c9e-c1f3667b31e8</guid><dc:creator>Andy Sinclair</dc:creator><description>&lt;p&gt;Hi.&lt;br /&gt;&lt;br /&gt;You are correct that this&amp;nbsp;is unlikely to work correctly, as as soon as ship mode is entered the SHPHLD button will be enabled to wake up the device.&lt;br /&gt;You can change the debounce time for waking up again, but it can&amp;#39;t be disabled.&lt;br /&gt;&lt;br /&gt;Is there a particular reason you would like to go to ship before the button is released?&lt;br /&gt;&lt;br /&gt;Andy&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Modifying the nPM1300 one button example</title><link>https://devzone.nordicsemi.com/thread/479053?ContentTypeID=1</link><pubDate>Tue, 16 Apr 2024 18:11:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b3a1f366-a2c7-4828-b2f2-84afc1256858</guid><dc:creator>backstreet.devisor</dc:creator><description>&lt;p&gt;Hi Andy.&lt;/p&gt;
&lt;p&gt;I don&amp;rsquo;t know what the reason is, but I also can&amp;rsquo;t enter ship mode from the work queue.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define WORKQ_THREAD_STACK_SIZE   1024
#define WORKQ_PRIORITY             5

K_THREAD_STACK_DEFINE(ship_mode_stack_area, WORKQ_THREAD_STACK_SIZE);

struct k_work_q ship_mode_work_q = {0};

static void ship_mode_work_cb (struct k_work *work){
	/* Enter to Ship mode*/
	LOG_INF(&amp;quot;Enter to SHIP MODE&amp;quot;);
	regulator_parent_ship_mode(regulators);
}

K_WORK_DEFINE(ship_mode_work, ship_mode_work_cb);

static void timer0_handler(struct k_timer *dummy)
{
	int ret;
    /*Interrupt Context - System Timer ISR */
	press_t = k_uptime_get() - press_t;
	LOG_INF(&amp;quot;timer0_handler function started. Press_time = %d&amp;quot;, press_t);
	if (vbus_connected) {
		LOG_INF(&amp;quot;Ship mode entry not possible with USB connected\n&amp;quot;);
		} else {
			k_work_submit(&amp;amp;ship_mode_work);
		}
}

K_TIMER_DEFINE(timer0, timer0_handler, NULL);

static void event_callback(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
{
	if (pins &amp;amp; BIT(NPM1300_EVENT_SHIPHOLD_PRESS)) {
		LOG_INF(&amp;quot;SHPHLD press&amp;quot;);
		press_t = k_uptime_get();
		/* start timer */
		k_timer_start(&amp;amp;timer0, K_MSEC(3000), K_NO_WAIT);
	}

	if (pins &amp;amp; BIT(NPM1300_EVENT_SHIPHOLD_RELEASE)) {
		LOG_INF(&amp;quot;SHPHLD release&amp;quot;);
		/* stop timer */
		k_timer_stop(&amp;amp;timer0);
	}

	if (pins &amp;amp; BIT(NPM1300_EVENT_VBUS_DETECTED)) {
		LOG_INF(&amp;quot;Vbus connected\n&amp;quot;);
		vbus_connected = true;
	}

	if (pins &amp;amp; BIT(NPM1300_EVENT_VBUS_REMOVED)) {
		LOG_INF(&amp;quot;Vbus removed\n&amp;quot;);
		vbus_connected = false;
	}
}

bool configure_events(void)...

int main(void)
{
    k_work_queue_init(&amp;amp;ship_mode_work_q);
    
    k_work_queue_start(&amp;amp;ship_mode_work_q, ship_mode_stack_area,
                    K_THREAD_STACK_SIZEOF(ship_mode_stack_area), WORKQ_PRIORITY, NULL);

	LOG_INF(&amp;quot;PMIC device ok&amp;quot;);

while (1) {
		led_on(leds, 2U);
		k_msleep(1000);
		led_off(leds, 2U);
		k_msleep(1000);
		fuel_gauge_update(charger);
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s the output on the terminal --&amp;gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/shphld-press.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;Perhaps the program enters ship mode, but immediately exits it, because the SHPHLD Press event is triggered (although I did not release the SHPHLD button).&lt;/p&gt;
&lt;p&gt;Logic level screen --&amp;gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/logic-level.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t know if it&amp;#39;s even possible to implement a function to enter ship mode and still keep the SHPHLD button pressed.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Modifying the nPM1300 one button example</title><link>https://devzone.nordicsemi.com/thread/478975?ContentTypeID=1</link><pubDate>Tue, 16 Apr 2024 12:21:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:980fc160-80f0-40c4-b68b-7c6a45af7fcf</guid><dc:creator>Andy Sinclair</dc:creator><description>&lt;p&gt;I don&amp;#39;t think you&amp;nbsp;can do this inside an ISR as it requires TWI&amp;nbsp;comms.&lt;br /&gt;You will have to set a flag and poll it in the background task, or setup a worker thread.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Modifying the nPM1300 one button example</title><link>https://devzone.nordicsemi.com/thread/478829?ContentTypeID=1</link><pubDate>Mon, 15 Apr 2024 16:55:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cd0db490-8347-4766-981d-448ef7a7d1fb</guid><dc:creator>backstreet.devisor</dc:creator><description>&lt;p&gt;Hi Sigurd!&lt;/p&gt;
&lt;p&gt;1.&amp;nbsp;In the default example (when the function regulator_parent_ship_mode() is inside event_callback()) everything works fine.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;2.&amp;nbsp;The return code is -5. But I don&amp;#39;t know what it means.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void timer0_handler(struct k_timer *dummy)
{
	int ret;
    /*Interrupt Context - System Timer ISR */
	press_t = k_uptime_get() - press_t;
	LOG_INF(&amp;quot;timer0_handler function started. Press_time = %d&amp;quot;, press_t);
	if (vbus_connected) {
		LOG_INF(&amp;quot;Ship mode entry not possible with USB connected\n&amp;quot;);
		} else {
			LOG_INF(&amp;quot;SHIP MODE&amp;quot;);
			ret = regulator_parent_ship_mode(regulators);
			LOG_INF(&amp;quot;ret = %d&amp;quot;, ret);
		}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Screen --&amp;gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/8715.return-code.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m hoping for your help.&lt;br /&gt;Thank you.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Modifying the nPM1300 one button example</title><link>https://devzone.nordicsemi.com/thread/478819?ContentTypeID=1</link><pubDate>Mon, 15 Apr 2024 14:38:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:18de4255-1b70-4645-9be7-c86c792ae3ad</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi!&lt;/p&gt;
&lt;p&gt;1) Do you see the same with the default, unmodified sample?&lt;/p&gt;
&lt;p&gt;2) Can you check the return code of&amp;nbsp;regulator_parent_ship_mode() ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>