I think they kind of covered it in Talking Bad. You could kind of think of it as Walt was going in the club house to die. Until he saw Jesse was not fully cooperating with them and was a prisoner did he decide to save him. The bullet was just a way for him to die after Jesse said no, I thought Walt was going to cause some type of chemical reaction in the cook room and blow it all up. In a way him saving Jesse and getting shot made the ending perfect. It let Jesse off the hook after the show is over, seeing how everyone still though Heisenberg was still cooking it all.
XI Wiki


